我使用NgJsTree (https://github.com/ezraroi/ngJsTree)来创建树。我希望保存用户选择的选项;因此,我将用户的选择和完整路径保存在一对变量中。在特定情况下,我以data.instance.get_node(data.selected[i])的方式获得完整路径,如下面的data.instance.get_path(data.node,'/');和所选节点
我使用此函数触发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这不是正确的方法吗?我做错了什么吗?
提前谢谢。
问候
发布于 2016-04-13 03:08:24
看起来你可能在给node.parents打电话,我也遇到过这种情况。另外,我会用不同的方式来处理你的问题。
我会:
var selectedNode = vm.treeInstance.jstree(true).get_selected();https://stackoverflow.com/questions/35621857
复制相似问题