2013-07-11 3 views
0

트리를 새로 고치는 방법을 찾았습니다. 모든 것이 잘 작동합니다. 하지만 이제는 특정 노드에 초점을 맞추기를 원하며 항상 _itemNodesMap이 정의되지 않았다고 말합니다. 포커싱dijit.Tree refresh 및 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이 정의되지 얻을 여기

내가 가진 것입니다. 왜? 트리가 표시되고 경로가 설정되며이 경로 이외의 모든 경로가 작동합니다. 좀 도와 줘서 대단 하시겠습니까? 감사!

답변

0

나는 경로를 설정하는 것은 너무 고려, 나는 당신의 then 기능에 트리 항목 (노드)에 초점을 다음 사용하는 것이 취한 당신의 scroll 함수에서 path 변수를 가정, 이연 과정이라고 생각 :

var item = myTree.path[path.length-1]; 
var nodes = myTree.getNodesByItem(item); 
if (nodes && nodes.length > 0 && nodes[0]) { 
    nodes[0].domNode.scrollIntoView(true); 
} 
+0

답장을 보내 주셔서 감사합니다. 지연을 사용하지 않고 this.set ('path', path);로 경로를 설정했습니다. – Sezunna

+0

코드를 사용하면 동일한 문제가 발생합니다. myTree.path (또는 내 경우에는 this.path [path.lenght-1])는 정의되지 않습니다. 보기의 경로가 나중에 올바르게 설정 되더라도. 지연 사용을 시도해야합니까? (전에 그렇게하지 않았기 때문에 나는 조금 미숙하다.) – Sezunna

+0

함수 호출은 다음과 같다 : dijit.byId ("myTree"). reload (data, path); dijit.byId ("myTree"). scroll (path); – Sezunna

0

하여 오류가 _itemNodesMap이 정의되지 _itemNodesMap과의 문제가되지 않습니다,하지만 그 경우 오히려 당신의 '이'당신이 스크롤 함수가 호출되는 곳의 지점 (가능성 통한에서 생각하는 것이 아니다 'this'에 대한 전역 객체를 사용하는 이벤트).

'dojo/_base/lang'과 lang.hitch 함수를 사용하여 'this'가 항상 원래 객체인지 확인해야합니다.

require([ 
    ... 
    "dojo/_base/lang" 
], function(..., lang){ 
... 
    scroll: lang.hitch(this, function(path){ 
     var itemnode = this._itemNodesMap[path[path.length-1]]; 
     this.focusNode(itemnode[0]); 
    }) 
.... 
}); 
+0

답변을 주셔서 감사합니다.하지만 코드를 추가 한 후에는 더 이상 Treeobject가 아니며 _itemNodesMap이없는 창이 다시 나타납니다. – Sezunna