Chr*_*row 15 javascript backbone.js marionette
问题
使用Backbone.Marrionette.Layout来呈现一些表格数据.<tbody>表的一部分是Backbone.Marionette.Region,用于显示Backbone.Marionette.CollectionView.
我无法弄清楚如何使用Marionette的"区域"来做到这一点,而不会通过在<tbody>元素中插入额外的HTML元素来搞乱表格显示.
示例代码
该Layout如下所示:
Backbone.Marionette.Layout.extend({
template:...
regions:{
list_region: '#list-region'
}
onRender:function(){
var collection = new TheCollection()
var collectionView = new TheCollectionView({
collection: collection
})
// PROBLEM: The region seems to needs its own HTML element,
// and the CollectionView also seems to need its on HTML
// element, but as far as I can see, there is only room
// for one element: <tbody>?
this.list_region.show(collectionView);
});
Run Code Online (Sandbox Code Playgroud)
布局的模板包含整个表格:
<table>
<tbody id='list-region'>
</tbody>
<tfoot id='footer-region'>
Some other stuff goes here that is not a collection, so I was able
to make the View's 'tagName' property 'tr', which worked fine.
</tfoot>
</table>
Run Code Online (Sandbox Code Playgroud)
有什么建议?
Der*_*ley 16
这种布局的目的仅仅是为了方便一张桌子吗?如果是这样,您应该考虑使用CompositeView.
RowView = Marionette.ItemView.extend({
tagName: "tr",
template: ...
});
TableView = Marionette.CompositeView.extend({
template: ...,
childView: RowView,
childViewContainer: "#list-region"
});
Run Code Online (Sandbox Code Playgroud)
这就是它.这会将所有itemView渲染到tbody中.