2012-06-29 30 views
1

我在嘗試使用javascript更新dijit.Tree的model.rootLabel。我設置的模式是這樣的:更新dijit.Tree的rootLabel

<div data-dojo-id="brandsModel" data-dojo-type="dijit.tree.ForestStoreModel" 
    rootId="0" 
    rootLabel="Brands (15)" 
    data-dojo-props="store:myStore, query:{}"> 

對於更新樹我已經擴展它像這樣(此代碼還與DND樹):

dojo.extend(dijit.Tree, { refreshModel:function() { 
    this._itemNodesMap = {}; 
    // Collapse root node and set model children to null, so the model 
    // will fetch again from the datastore when _expandNode() is called 
    this._collapseNode(this.tree.rootNode); 
    this.model.root.children = null; 
    // Set root NODE to unchecked so that Tree will fetch from the model again 
    this.rootNode.state = "UNCHECKED"; 
//Set _loadFinished to false, so a new fetch is possible 
this.model.store._loadFinished = false; 
this._expandNode(this.tree.rootNode); 
} 
}); 

從添加或刪除項目後樹我也試着更新櫃檯。我嘗試過:用console.debug(樹)在調試的時候,但我不知道有什麼用實際顯示更改標籤

tree.model.rootLabel = 'Brands (16)'; 
tree.model.root.label = 'Brands (16)'; 

的變化顯示。

回答

2

rootnode不是商店中的實際商品 - 只有'_itemNodesMap'中的東西被刷新。你將需要設置rootnode的標籤節點的innerHTML。

tree.rowNode.set("label", "Brands (" + tree._itemNodesMap.lenght + ")"); 
+0

非常感謝!它適用於:tree.rootNode.set(「label」,「Brands(16)」); – noru