Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tree dijit.树刷新和焦点节点_Tree_Dojo - Fatal编程技术网

Tree dijit.树刷新和焦点节点

Tree dijit.树刷新和焦点节点,tree,dojo,Tree,Dojo,我发现了如何刷新一棵树,一切都很好。但是现在我想关注一个特定的节点,它总是说_itemNodeMap是未定义的 以下是我所拥有的: require([ "dojo/_base/window", "dojo/data/ItemFileWriteStore", "dijit/tree/ForestStoreModel", "dijit/Tree", "dojo/domReady!" ], function(win, Ifrs, ForestStoreMo

我发现了如何刷新一棵树,一切都很好。但是现在我想关注一个特定的节点,它总是说_itemNodeMap是未定义的

以下是我所拥有的:

    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]);
   }

但我总是觉得_itemnodemap是未定义的。为什么?树被显示,路径被设置,除此之外的一切都可以工作。如果能得到帮助就太好了。谢谢

我认为设置路径是一个延迟的过程,因此假设
滚动
函数中的
路径
变量已考虑到这一点,我将使用以下内容来关注
函数中的树项(节点):

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

如果您的错误是_itemNodesMap未定义,则_itemNodesMap没有问题,而是您的“this”不是您认为在调用scroll函数的地方(可能是通过一个事件,它可能使用全局对象来实现“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]);
    })
....
});

谢谢你的回答。我没有使用任何延迟,只是用这个设置路径。set('path',path);现在使用代码会导致同样的问题。myTree.path(在我的例子中是this.path[path.lenght-1])未定义。即使之后视图中的路径设置正确。我应该试着用延期付款吗?(以前从未这样做过,所以我有点经验不足)函数调用是:dijit.byId(“myTree”).reload(数据,路径);dijit.byId(“myTree”).scroll(路径);你的道路是什么?我假设您已经知道要滚动到哪个项目,并且已经构建了该项目的路径。如果是这样,上述代码应该可以工作(因为它适用于我的应用程序)。至于使用延迟设置路径,请参阅此错误报告:是的,在我的路径中是id。但不幸的是,即使我有id,您的代码也无法工作。在“节点”中,它告诉我它未定义。但我可以确信,在树完全构建之后(在设置路径时正确选择了它!),该项就在树中。当我现在第二次点击时,没有重新加载,只是对焦,一切都正常(_itemnodemap也正确填充)。我的猜测是,当代码运行时,树不是完全构建的。我可以强迫他等待吗?谢谢你的回答,但是在添加代码后,这不再是Treeobject,而是窗口,它不再有_itemNodeMap。