How to select a specific node programmatically?

前端 未结 9 968
小鲜肉
小鲜肉 2021-02-02 07:18

I have a jstree. I want to select the node which is bound to the object which has a location with id of 158. This works but seems stupid. What\'s the more idiomatic way of doing

9条回答
  •  独厮守ぢ
    2021-02-02 07:52

    If you're populating the tree using HTML instead of JSON data and wondering how to set the node_id, you just need to set the id attribute of the

  • element!

    Then

    $('.tree-menu')
        .jstree(true)
        .select_node("node_3");
    

    will select the Node 3 - Level 2 node.

    For those getting javascript errors, remember to use Full version of jQuery, not the slim version!

    For all down voters, here is the demo to prove it's working: https://jsfiddle.net/davidliang2008/75v3fLbs/7/

提交回复
热议问题