我尝试使用marionette compositeView构建Tree Table组件。
与this类似。
我参考Derick's sample使用marionettejs构建树状菜单。
// The recursive tree view
var TreeView = Backbone.Marionette.CompositeView.extend({
template: "#node-template",
tagName: "ul",
initialize: function(){
this.collection = this.model.nodes;
}
});
// The tree's root: a simple collection view that renders
// a recursive tree structure for each item in the collection
var TreeRoot = Backbone.Marionette.CollectionView.extend({
childView: TreeView
});
我试图使用Table而不是UnOrder列表,根据树的深度将CSS类应用于每个TR。
但是在这里我无法找到一个API来在渲染时获得模型的深度。在递归调用期间有没有办法获得深度?
答案 0 :(得分:0)
仅供参考:不推荐使用CompositeView进行删除
然而,为了做深度的事情,我认为你可以做这样的事情:
depth: 0,
childViewOptions: function(){
return {
depth: this.getOption('depth') + 1;
};
}
在此示例中,默认深度为0,但后续子项将作为选项传递深度。