更新dijit.Tree的rootLabel

时间:2012-06-29 11:26:15

标签: dojo store dijit.tree

我正在尝试使用javascript更新dijit.Tree的model.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);
}
});

在树中添加或删除项目后,我也尝试更新计数器。我试过了:

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

使用console.debug(树)进行调试时会显示更改,但我不知道用什么来实际显示更改后的标签。

1 个答案:

答案 0 :(得分:2)

rootnode不是商店中的实际商品 - 只有'_itemNodesMap'中的内容才会被刷新。你需要设置rootnode's-labelnode的innerHTML。

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