我想尝试使用:
{{#each content as |product index|}}
{{index}}
{{/each}}
但我的应用程序有 itemContoller,如下所示:
{{#each product in content itemController='product'}}
如果我这样设置:
{{#each content as |product index| itemController='product'}}
这不起作用!我找到了所有的ember指南,但没有找到答案。
请提供任何帮助。
控制器(Object
, Array
and itemController
)即将消失。做事的新方法是使用组件。
因此,您可以定义一个组件,而不是项目控制器:
App.MyProductComponent = Ember.Component.extend({
myIndex: function(){
return this.get('passedIndex') + 1;
}.property('passedIndex')
});
然后,在你的#each
您可以按如下方式使用它:
<script type="text/x-handlebars" data-template-name="index">
<ul>
{{#each model as |product index|}}
{{ my-product passedIndex=index product=product }}
{{/each}}
</ul>
</script>
工作溶液here http://emberjs.jsbin.com/lixebi/1/edit?html,js,console,output
请参阅以下链接并搜索itemController
- https://github.com/emberjs/rfcs/pull/15 https://github.com/emberjs/rfcs/pull/15
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)