jsTree - loading subnodes via ajax on demand

前端 未结 5 1646
夕颜
夕颜 2020-11-29 03:51

I\'m trying to get a jsTree working with on demand loading of subnodes. My code is this:

jQuery(\'#introspection_tree\').jstree({ 
        \"json_data\" : {
              


        
5条回答
  •  余生分开走
    2020-11-29 04:36

    I spended hours on this problem. Finally i got it that way:

    $("#resourceTree").jstree({
        "types": {
          "default": {
            "icon": "fa fa-folder-open treeFolderIcon",
          }
        },
        "plugins": ["json_data", "types", "wholerow", "search"],
        "core": {
          "multiple": false,
          "data": {
            "url" : function(node){
              var url = "rootTree.json";
              if(node.id === "specialChildSubTree")
                url = "specialChildSubTree.json";
              return url;
            },
            "data" : function(node){
              return {"id" : node.id};
            }
          }
        },
      });
    

    rootTree.json:

    [
      {
        "text": "Opened root folder",
        "state": {
          "opened": true
        },
        "children": [
          {
            "id" : "specialChildSubTree",
            "state": "closed",
            "children":true
          }
        ]
      }
    ]
    

    specialChildSubTree.json:

    [
      "Child 1",
      {
        "text": "Child 2",
        "children": [
          "One more"
        ]
      }
    ]
    

    So i mark the node that become the parent of the ajax loaded subtree with an id, i watch for in the core configuration.

    NOTE: That node must have the "state" : "closed" parameter and it must have the parameter "children" : true.

    I am using jsTree.js in version 3.3.3

提交回复
热议问题