如何呈现每个关联都有自己的控制器
所以我的模型设置如下:
So my models are set up like this :
App.Post = DS.Model.extend
comments: DS.hasMany 'App.Comment'
App.Comment = DS.Model.extend
post: DS.belongsTo 'App.Post'
我正在尝试创建一个包含所有帖子和所有评论的视图,但我需要装饰评论对象。
I'm trying to create a view that has all posts and all comments display, but I need to decorate the comment objects.
这是我想要做的,但无济于事:
This is what I'd like to do but, to no avail :
<ul>
{{#each post in controller}}
<li>{{post.title}}</li>
<ol>
{{#each comment in post.comments itemController="comment"}}
<li>{{comment.body}}</li>
{{/each}}
</ol>
{{/each}}
</ul>
在 App.CommentController
中定义的属性是
我怀疑 Ember.OrderedSet
不实现 itemController
param - 是否有解决方法?
I suspect that Ember.OrderedSet
does not implement the itemController
param - is there a workaround for this?
您需要使用新的失效控制标签。这将加载指定类型的视图和控制器:
You need to use the new expiremental control tag. This will load the view and controller for the specified type:
<ul>
{{#each post in controller}}
<li>{{post.title}}</li>
<ol>
{{#each comment in post.comments}}
{{ control "comment" comment }}
{{/each}}
</ol>
{{/each}}
</ul>
您需要先启用此过期功能。在加载ember之前加载:
You will need to enable this expiremental feature first. Put this before ember is loaded:
<script type='application/javascript'>
ENV = {
EXPERIMENTAL_CONTROL_HELPER: true
};
</script>
另外,您需要指定控制器的注释不应该是单例,否则将只有一个控制器实例化为所有评论视图:
Also, you will need to specify that the controller for comments should not be a singleton, otherwise there will only be one controller instantiated for all comment views:
// this is needed to use control handlebars template properly per
// https://github.com/emberjs/ember.js/issues/1990
App.register('controller:comment', App.CommentController, {singleton: false });