2016-10-04 99 views
0

我曾试图用木偶组合视图来构建树表组件。获取树模型数据的深度 - 复合视图 - marionettejs

类似于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

FYI:CompositeView中已被弃用去除

但是做深度的事情我想你可以做这样的事情:

depth: 0, 
childViewOptions: function(){ 
    return { 
    depth: this.getOption('depth') + 1; 
    }; 
} 

在这个例子中默认的深度是0,但随后孩子会有深度作为选项通过。