问题描述
我想尝试使用:
{{#each content as |product index|}}
{{index}}
{{/each}}
但是我的应用程序有itemContoller,像这样:
But my app has the itemContoller, like this:
{{#each product in content itemController='product'}}
如果我设置:
{{#each content as |product index| itemController='product'}}
它不工作!我找到所有的Ember指南,没有找到答案。
It doesn't work! I found all of the ember guides and did not find the answer.
请帮助。
推荐答案
控制器( Object
, Array
和 itemController
)正在消失。新事物的方法是使用一个组件。
Controllers (Object
, Array
and itemController
) are going away. The new way to do things is by using a component.
所以,而不是您的项目控制器,您可以定义一个组件:
So, instead of your item controller, you would define a component:
App.MyProductComponent = Ember.Component.extend({
myIndex: function(){
return this.get('passedIndex') + 1;
}.property('passedIndex')
});
然后,在你的 #each
帮助器将使用如下:
Then, inside your #each
helper you would use it as follows:
<script type="text/x-handlebars" data-template-name="index">
<ul>
{{#each model as |product index|}}
{{ my-product passedIndex=index product=product }}
{{/each}}
</ul>
</script>
工作解决方案
查看以下链接,并搜索 itemController
-
See the following link and do a search for itemController
- https://github.com/emberjs/rfcs/pull/15
这篇关于如何将itemController设置为(ember 1.11 beta3)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!