2

Hi I am new to JsTree and I got a question on event. Let's call the tree structure stuff as LeftSide and the content rendered after you click one node on the tree as RightSide. What I can do is that you click one node at LeftSide then there is a subpage will be rendered at RightSide.

Now, what I need is to click something on the RightSide (This "something" can be a node name on the LeftSide) and it will render a subpage on the RightSide as same as if you click that node on the LeftSide.

I am not sure whether I make my question clear.

The point is that I don't know how to describe my question and search it one the web. So if you don't know the exact answer, you you just tell me which direction I should search for it. (If you tell me to read the official document, please specify which part rather than the whole doc.)

Appreciate for any help!!!

4

2 回答 2

3

我不认为“select_node.jstree”事件是最好的解决方案,因为当你刷新树时,它也会被触发。下面的代码片段是我使用的方式:</p>

$("#categories_tree").on("click", ".jstree-anchor", function(e) {
   var id = $("#categories_tree").jstree(true).get_node($(this)).id;
})

编辑:修复了一个右括号

于 2015-08-14T02:27:08.907 回答
2

您想监听select_node.jstree事件,并获取选定的节点。然后,您可以在页面右侧执行您想要的操作。

$("#jstree_id").on('select_node.jstree', function(e) {
    // gather ids of selected nodes
    var selected_ids = [];
    $("#jstree_id").jstree('get_selected').each(function () { 
        selected_ids.push(this.id); 
    }); 
    // do summit with them
    $('#RightSide').text('selected '+selected_ids);
});

编辑为bind已弃用以支持on.

于 2013-06-14T12:51:55.370 回答