4

我的网站上有一个花哨的树解决方案,我想有一个按钮来触发特定节点。

我可以通过单击按钮激活特定节点或在精美树加载后触发它吗?

我的花式树代码:

  $("#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();
4

1 回答 1

8

The .getNodeByKey is just expecting the "id" of the node element. For example to get the "Sample Node" from the following example just set the id for each element:

<div id="tree">
    <ul>
        <li id="123">Sample Node</li>
    </ul>
</div>

And use something like this to activate it:

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

I recommend adding this to the "init: function() {}" otherwise it may not activate if the tree is still loading/building.

Can also use the following from within the "init:", should do the same.

data.tree.activateKey("123")

Finally, to get the key if you don't already know it:

click: function (event, data) {
    var node = data.node;
    alert("ID: " + node.key);
}
于 2015-01-29T22:32:17.950 回答