如何在原型中显示词汇标题?
我希望我的自定义类型显示存储的词汇表的标题。字段定义如下所示:
atapi.LinesField(
'member_field',
searchable=1,
index='KeywordIndex',
multiValued=1,
storage=atapi.AnnotationStorage(),
vocabulary_factory='member_name',
widget=AutocompleteWidget(
label=_(u"Member Name"),
description=_(u"Multiple Lines, One Per Line."),
actb_timeout=-1,
actb_expand_onfocus=0,
actb_filter_bogus=0,
),
enforceVocabulary=0,
),
词汇表定义如下所示:
class member_name(object):
implements(IVocabularyFactory)
def __call__(self, context=None):
items = (
SimpleTerm(value='john', title=u'John Doe'),
SimpleTerm(value='paul', title=u'Paul Smith'),
... ...
)
return SimpleVocabulary(items)
member_nameFactory = member_name()
相应的页面模板如下所示:
<div tal:define="mbrs context/member_field|nothing"
tal:condition="mbrs">
Member List:
<span tal:repeat="mbr mbrs">
<span tal:replace="mbr">Member Name</span>
<span class="separator"
tal:condition="not: repeat/mbr/end" tal:replace="string:, " />
</span>
</div>
仅显示值的示例结果如下所示: 成员列表: paul , john
。我怎样才能显示他们的头衔,例如:成员列表:Paul Smith、John Doe
?
I want my custom type to display the stored vocabulary's title. The field definition looks like:
atapi.LinesField(
'member_field',
searchable=1,
index='KeywordIndex',
multiValued=1,
storage=atapi.AnnotationStorage(),
vocabulary_factory='member_name',
widget=AutocompleteWidget(
label=_(u"Member Name"),
description=_(u"Multiple Lines, One Per Line."),
actb_timeout=-1,
actb_expand_onfocus=0,
actb_filter_bogus=0,
),
enforceVocabulary=0,
),
The vocabulary definition looks like:
class member_name(object):
implements(IVocabularyFactory)
def __call__(self, context=None):
items = (
SimpleTerm(value='john', title=u'John Doe'),
SimpleTerm(value='paul', title=u'Paul Smith'),
... ...
)
return SimpleVocabulary(items)
member_nameFactory = member_name()
The corresponding page template looks like:
<div tal:define="mbrs context/member_field|nothing"
tal:condition="mbrs">
Member List:
<span tal:repeat="mbr mbrs">
<span tal:replace="mbr">Member Name</span>
<span class="separator"
tal:condition="not: repeat/mbr/end" tal:replace="string:, " />
</span>
</div>
The example result, showing only values, looks like: Member List: paul , john
. How can I display their titles instead, like: Member List: Paul Smith , John Doe
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
词汇表(Zope3 风格)只是命名的实用程序,您可以像这样检索它们:
然后您可以获得术语的标题,如下所示:
更多信息:
Vocabularies (in Zope3 style) are just named utilities and you can retrieve them like this:
and then you can get the term's title like this:
More info: