我正在尝试使用 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(tree) 调试时会显示更改,但我不知道使用什么来实际显示更改的标签。