2016-10-04 86 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,但隨後孩子會有深度作爲選項通過。