Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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
Javascript Fancytree在单击按钮时激活节点_Javascript_Jquery_Fancytree - Fatal编程技术网

Javascript Fancytree在单击按钮时激活节点

Javascript Fancytree在单击按钮时激活节点,javascript,jquery,fancytree,Javascript,Jquery,Fancytree,我在我的网站上有一个奇特的树解决方案,我想有一个按钮,将触发一个特定的节点 我可以通过单击按钮激活特定节点,还是在加载花式树后触发它 我的fancytree代码: $("#tree").fancytree({ //Fancy Tree checkbox: false, selectMode: 3, extensions: ["dnd"], source: { url: "@(Url.Action("Get

我在我的网站上有一个奇特的树解决方案,我想有一个按钮,将触发一个特定的节点

我可以通过单击按钮激活特定节点,还是在加载花式树后触发它

我的fancytree代码:

  $("#tree").fancytree({ //Fancy Tree
        checkbox: false,
        selectMode: 3,
        extensions: ["dnd"],
        source: {
            url: "@(Url.Action("GetCategoryForFancyTree", "LinksDocuments"))" + '?time=' + timestamp,
                success: function(data){

                    console.log(data);
                },
                cache: true
            }
     });
我看到这个代码可能我可以使用,但我不知道节点的节点密钥,我如何检索密钥

$("#tree").fancytree("getTree").getNodeByKey("id4.3.2").setActive();

.getNodeByKey只需要节点元素的“id”。例如,要从以下示例中获取“示例节点”,只需设置每个元素的id即可:

<div id="tree">
    <ul>
        <li id="123">Sample Node</li>
    </ul>
</div>
我建议将其添加到“init:function(){}”中,否则如果树仍在加载/构建,它可能不会激活

也可以从“init:”内使用以下命令,应执行相同的操作

data.tree.activateKey("123")
最后,如果您还不知道密钥,请执行以下操作:

click: function (event, data) {
    var node = data.node;
    alert("ID: " + node.key);
}
$(“#树”).fancytree(“getTree”).activateKey(false)
用于重置激活节点
click: function (event, data) {
    var node = data.node;
    alert("ID: " + node.key);
}