[英]How can I add a <thead> section to a marionette collectionview with tagName: 'table'?
I have a collection view that looks something like this: 我有一个看起来像这样的集合视图:
var PersonView = Marionette.ItemView.extend({
tagName: 'tr',
template: function (model) {
return _.template("<td><%= data.firstName %></td><td><%= data.lastName %></td>", {
firstName: model.firstName,
lastName: model.lastName
}, { variable: 'data' });
}
}),
PersonCollectionView = Marionette.CollectionView.extend({
tagName: 'table',
itemView: PersonView
});
It works fine, but I can't figure out the best way to add a <thead>
section to my table. 它工作正常,但我想不出在表中添加
<thead>
节的最佳方法。 I thought of changing tagName: 'table'
to tagName: 'tbody'
and adding the thead
section in the layout which displays the collection view, but it doesn't look like a very clean approach. 我想到了将
tagName: 'table'
更改为tagName: 'tbody'
并在显示集合视图的布局中添加thead
部分,但这看起来不是很干净的方法。 Indeed, if I were to use my collection view elsewhere, I would have to reproduce the thead
section in another layout... What is the proposed way of doing this? 确实,如果要在其他地方使用收藏视图,则必须以另一种布局重现
thead
部分。建议的实现方式是什么?
PS See https://github.com/shawninder/table-collection-views for a working example. PS请参阅https://github.com/shawninder/table-collection-views以获取工作示例。 You'll notice the table has no
<thead>
section, which is what I'm trying to solve. 您会注意到该表没有
<thead>
部分,这是我要解决的问题。
UPDATE: Fixed with this commit based on accepted answer 更新: 此修复基于已接受的答案进行此提交
You may need to use the CompositeView instead. 您可能需要改用CompositeView 。 With
CompositeView
you can provide a template which adds your thead
and use the ItemViewContainer
to render you collections. 使用
CompositeView
您可以提供一个模板来添加thead
并使用ItemViewContainer
呈现您的收藏集。 Read the doc and I am sure you will figure out the solution. 阅读文档 ,我相信您会找到解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.