【发布时间】:2016-03-31 19:21:01
【问题描述】:
如最新Marionette docs中所述:
CompositeView已弃用。您应该在Region.show上使用replaceElement选项和 将CollectionView渲染到View内的区域中以实现此功能。
我还是不明白现在应该如何实现CompositeView 功能。
以前,CompositeView 非常适合与此类模板一起使用:
<script id="table-template" type="text/html">
<table>
<% if (items.length) { %>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<% } %>
<tbody></tbody>
<tfoot>
<tr>
<td colspan="3">some footer information</td>
</tr>
</tfoot>
</table>
new MyCompositeView({
template: "#table-template",
templateContext: function() {
return { items: this.collection.toJSON() };
}
// ... other options
});
如果我们决定使用LayoutView 而不是CompositeView,那么我们需要手动编写大量事件绑定(例如根据集合中的项目数显示/隐藏表头)。这让事情变得更加困难。
没有CompositeView,还有什么干净而不复杂的生活方式吗?
感谢您的任何帮助或建议。
【问题讨论】:
标签: backbone.js handlebars.js marionette underscore.js-templating