Collections Ember是否有可与{{{collection}一起使用的{{{itemView}}帮助程序?

Collections Ember是否有可与{{{collection}一起使用的{{{itemView}}帮助程序?,collections,ember.js,each,Collections,Ember.js,Each,实际上,我正在寻找让视图负责标记集合视图中的第一项或最后一项的方法,我找到了这个方法 .但我不想在javascript中定义itemViewClass模板的属性(例如类名),我可以使用{{itemView}}帮助器或其他东西来定义itemView模板吗 {{#collection contentBinding="dataList" tagName="ol" classNames="list" itemViewClass="ItemView"}} {{#itemView className

实际上,我正在寻找让视图负责标记集合视图中的第一项或最后一项的方法,我找到了这个方法 .但我不想在javascript中定义itemViewClass模板的属性(例如类名),我可以使用{{itemView}}帮助器或其他东西来定义itemView模板吗

{{#collection contentBinding="dataList" tagName="ol" classNames="list" itemViewClass="ItemView"}}
    {{#itemView classNames="item" classNamesBinding="isLastItem:last"}}
        item templates
    {{/itemView}}
{{/collection}}

虽然这可以通过其他方式解决,但我只想知道是否可以找到内置的支持。我搜索了很长时间,只是找不到
Ember.handlebar.collection
的文档,它不在最新的API文档中。

从Emberjs的主版本开始,您可以尝试使用自定义的handlebar“绑定”助手。 它看起来像这样:

{{#each item in collection}}
    {{#isLastElement item}}
        template if last
    {{else}}
        template if not
    {{/isLastElement}}    

    both templates
{{/each}}


Ember.Handlebars.registerBoundHelper('islastElement', 
    function(item, options) {
     if(functionTellingIfThisIsLastElement(item))
          return options.fn(this);
     else
          return options.inverse(this);
    }
);

这只是查看事物的另一种方式,使用函数告诉IfthisLasteElement查看集合或项目中的属性。要访问该集合,您必须在此处更改一些内容,以获得良好的上下文+参数,具体取决于您的代码。

您正在查找
itemClassNames
及类似内容。文档是,但由于某种原因,它看起来没有被编译到API文档中。编辑-看起来
{{collection}}
已被弃用。您仍然可以通过选中复选框查看文档。谢谢您的建议
itemClassNames
很有用,但是
itemClassNameBindings
似乎不起作用,或者我用错了。稍后我会在这里举一个例子。您使用的是
itemclasnamebindings
还是
itemclasnamebindings
?我使用的是
itemclasnamebindings
。这是正确的拼写,对吗?{{..itemClassNameBindings=“propertyInItemView或itemView.propertyInItemView”},我尝试过这种用法,但不起作用。