渲染多个视图/控制器对 [英] Render Multiple View/Controller Pairs
问题描述
我目前正在呈现视图列表:
I am currently rendering a list of views:
<ul>
{{#each newsItem in controller}}
{{view App.NewsItemView contentBinding="newsItem" class="news-item" }}
{{/each}}
</ul>
但我想在每个视图中注入一个NewsItemController。
But I would like to inject a NewsItemController into each view.
我试过使用 render
,但是这似乎只支持一个视图,给出异常:
I've tried using render
, but this only seems to support a single view, giving the exception:
未捕获错误:Handlebars错误:无法在对象上找到属性control
。
Uncaught Error: Handlebars error: Could not find property 'control' on object .
我发现简单提及使用控制
,但这似乎不包括。
I've found a brief mention of using control
instead, but this no longer seems to be included.
那么,如何渲染同一个视图的多个版本,为每个版本注入一个单独的控制器?
推荐答案
{{render}}
应该固定在当前master中(如果你从Github构建它)。如果您传递模型,则应该可以多次使用它:
{{render}}
should be fixed in current master (if you build it from Github). You should be able to use it multiple times if you pass a model:
<ul>
{{#each controller}}
{{render "newsItem" this}}
{{/each}}
</ul>
{{control}}
但隐藏在一个标志后面(因为它仍然是实验性的)。要使用它,您需要在包含 ember.js
文件之前执行: ENV.EXPERIMENTAL_CONTROL_HELPER = true
如果你可以避免使用它,它会更好。
{{control}}
is still there but hidden behind a flag (because it's still experimental). To use it you need to do : ENV.EXPERIMENTAL_CONTROL_HELPER = true
before including the ember.js
file. If you can avoid using it, it would be better.
但我认为最简单的方法是使用 itemController
:
However I think the simplest approach would be to use itemController
:
<ul>
{{#each controller itemController="newsItem"}}
{{view App.NewsItemView class="news-item" }}
{{/each}}
</ul>
我认为你可以结合它们使它更简单/ p>
I think you can combine them to make it simpler (I haven't tried it yet):
<ul>
{{each controller itemController="newsItem" itemViewClass="App.NewsItemView"}}
</ul>
这篇关于渲染多个视图/控制器对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!