【发布时间】:2014-07-26 18:44:13
【问题描述】:
我有一个名为 IndexView() 的木偶复合视图。它与名为 index.html 的车把模板相关联。
在我继续之前,我会注意到我知道我可以简单地渲染一个绑定到复合视图的项目视图来输出集合中的每个模型。我会这样做,但我想问我的问题以求理解。
我从 url "/api/users" 获取一个集合
然后得到一个这样的列表
[{"name": "John Doe", "age": 30 }, {"name":"Jane Doe", "age": 31}]
在我的用户控制器中我有代码
var usersCollection = new UsersCollection();
App.contentRegion.show(new IndexView({collection: usersCollection}));
usersCollection.fetch();
如何遍历模板中的集合?
例如
{{#each ????}}
<li> {{name}} {{age}} </li>
{{/each}}
问号在哪里?从 ItemView 的木偶文档中,它将是项目。 CollectionView 或 CompositeView 会是什么?
【问题讨论】:
-
您可以发布您的 IndexView 代码吗?
-
就是 Marionette.CompositeView.extend({template: Template});它在一个 require 模块中,所以在这里发布它不会给你很多细节。这个问题只是让我看看是否有办法做到这一点。我实际上并没有打算以这种方式使用复合视图,我只是好奇。
标签: marionette