How to associate a data to a node in jstree?

后端 未结 7 1905
温柔的废话
温柔的废话 2020-12-29 07:12
$(\"#ifTree\").jstree({
            \"plugins\" : [\"themes\",\"html_data\",\"ui\",\"crrm\"], 
            \"themes\" : {
                    \"theme\" : \"apple\",
         


        
7条回答
  •  旧时难觅i
    2020-12-29 08:02

    Plz refer to the Author's answer.

    You could edit info by $('#tree').jstree(true).get_node("some_node_id"), and post the extra data as json by $('#tree').jstree(true).get_json("some_node_id").

    You can add anything you want to the data object. Like:
    { "id" : "some_node_id" "text" : "some node", ... "data" : { "foo" : "bar", "example_array" : ["1",2,true], "obj" : {"asdf":"asdf1"}  } ...
    
    And later on you can retrieve it like so:
    $('#tree').jstree(true).get_node("some_node_id").data.obj.asdf; // this would equal "asdf1"
    $('#tree').jstree(true).get_node("some_node_id").data.example_array; // this would be an array: ["1",2,true]
    
    Setting other values is just as simple - you are working with a normal object:
    $('#tree').jstree(true).get_node("some_node_id").data.obj.asdf = "some other value";
    $('#tree').jstree(true).get_node("some_node_id").data.example_array = "I do not want this an array anymore";
    $('#tree').jstree(true).get_node("some_node_id").data.obj.new_property = 1024;
    

提交回复
热议问题