How to select a specific node programmatically?

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

    Based on jsTree groups you can try

    jQuery("#getStartedTree").jstree("select_node", "#test2"); 
    

    if the data looks like

    The JSON in the TextFile.txt - borrowed from your simple example
     [
         {
         "data" : "A node",
         "children" : [ "Child 1", "Child 2" ]
         },
         {
         "attr" : { "id" : "test1" },
             "data" : {
                 "title" : "Long format demo",
                 "attr" : { "id" : "test2", "href" : "#" }
             }
         }
     ] 
    

    and jsTree set up

    My tree container is 
    My jsTree code $("#getStartedTree").jstree({ "themes": { "theme": "default", "url": "../App_Css/Themes/Default/style.css", "dots": true, "icons": true }, "json_data": { "ajax": { "url": "../SiteMaps/TextFile.txt", "dataType": "json", "data": function(n) { return { id: n.attr ? n.attr("id") : 0 }; } } }, "plugins": ["themes", "json_data", "ui"] });

    Is that what you are after?

提交回复
热议问题