我發現如何刷新一棵樹,一切正常。但是現在我想關注一個特定的節點,它總是說_itemNodesMap是未定義的。dijit.Tree refresh and focusNode
以下是我有:
require([
"dojo/_base/window", "dojo/data/ItemFileWriteStore",
"dijit/tree/ForestStoreModel", "dijit/Tree",
"dojo/domReady!"
], function(win, Ifrs, ForestStoreModel, Tree){
dojo.extend(Tree, {
reload: function (data, path) {
this.dndController.selectNone();
this.model.store.clearOnClose = true;
this.model.store.close();
this._itemNodesMap = {};
this.rootNode.state = "UNCHECKED";
this.model.root.children = null;
this.rootNode.destroyRecursive();
var _data = {identifier: "id", label: "label", items: data};
var _store = new Ifrs({data:_data});
var _treeModel = new ForestStoreModel({
store: _store,
rootId:"root",
rootLabel:"Things",
childrenAttr:["children"]
});
this.model.constructor(_treeModel);
this.postMixInProperties();
this._load();
path.unshift("root");
this.set('path',path);
}});
用於聚焦我嘗試添加以下內容並設置路徑後調用它:
scroll : function(path){
var itemnode = this._itemNodesMap[path[path.length-1]];
this.focusNode(itemnode[0]);
}
但我總是拿到_itemNodesMap是不確定的。爲什麼?顯示樹,路徑設置,除此之外的所有內容都可以工作。會很好,得到一些幫助。謝謝!
謝謝您的回答。我沒有使用任何延遲,只是用this.set('path',path)設置路徑; – Sezunna
現在使用你的代碼會導致同樣的問題。 myTree.path(或者在我的情況下,它是this.path [path.lenght-1])未定義。即使之後視圖中的路徑設置正確。我應該嘗試使用延期嗎? (從來沒有這樣做過,所以我有點經驗不足) – Sezunna
函數調用是:dijit.byId(「myTree」)。reload(data,path); dijit.byId( 「myTree」)滾動(路徑)。; – Sezunna