我正在使用 NgJsTree ( https://github.com/ezraroi/ngJsTree ) 创建一棵树。我希望保存用户选择的选项;所以我将用户的选择和完整路径保存在一对变量中。在特殊情况下,我得到像这样的完整路径 data.instance.get_path(data.node,'/');
以及以这种方式选择的节点 data.instance.get_node(data .selected[i])
我使用此函数触发 loaded
事件:
openSelectedNode = function(e, data){
var nodes = config.path.split("/");
for(var i=0;i<nodes.length;i++){
$(this).jstree("open_node", $('#' + nodes[i].replace(" ", "")));
}
$(this).jstree('select_node', $('#' + nodes[nodes.length-1] ));
}
这样,当加载树时,我可以重新打开树并选择正确的节点。该代码有效,但在控制台中出现此错误:
Uncaught TypeError: Cannot read property 'parents' of undefined
这不是正确的方法吗?我有什么错误吗?
提前致谢。
问候
最佳答案
看起来你可能在某个地方调用了node.parents,这发生在我身上。另外,我会以不同的方式处理你的问题。
我会:
使用ngJStree提供的实例来引用树,然后使用
var selectedNode = vm.treeInstance.jstree(true).get_selected();
- 存储该节点 ID,然后在下次创建树之前将其状态设置为“selected: true”。应该已经这样选择了。
关于javascript - ngjstree : error when select node automatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35621857/