【问题标题】:Updating the rootLabel of a dijit.Tree更新 dijit.Tree 的 rootLabel
【发布时间】:2012-06-30 22:27:28
【问题描述】:

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

【问题讨论】:

    标签: dojo store dijit.tree


    【解决方案1】:

    根节点不是存储中的实际项目 - 只有“_itemNodesMap”中的内容才会被刷新。您需要设置根节点的标签节点的 innerHTML。

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

    【讨论】:

    • 非常感谢!它适用于:tree.rootNode.set("label", "Brands (16)");
    猜你喜欢
    • 2012-02-23
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 2010-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多