How to select a specific node programmatically?

前端 未结 9 1119
小鲜肉
小鲜肉 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:49

    This solution Works for me

    // after the tree is loaded
    $(".jstree").on("loaded.jstree", function(){
        // don't use "#" for ID
        $('.jstree').jstree(true).select_node('ElementId');
    });
    

    and even in a php loop (dynamically) :

    $(".jstree").on("loaded.jstree", function(){
        
            $('.jstree').jstree(true).select_node('');
        
    });
    

    Hope this works for you.

提交回复
热议问题