Lazy loading with jsTree

前端 未结 5 1049
一向
一向 2021-02-07 10:45

I am trying to dynamically load the nodes of a jtree when they are expanded. The little documentation I found is at the end of this page.

I found some solutions that cre

5条回答
  •  天涯浪人
    2021-02-07 10:56

    I'll give you that the documentation/examples is pretty rough. I'll also add that the source of your confusion comes from a major upgrade - the old version doesn't have much in common with the new version and unfortunately most examples were written against that old version.

    The good news is that lazy loading is supported out of the box, it just isn't that obvious. The key is that it does call your data: config as each node is expanded. But in order for it to work, the URL function must return a different URL for the given node. In the code below, note the condition to return one URL if the node is root (#), and another if it is not.

    $('#TreeDiv')
      .jstree({
        core: {
          data: {
            url: function (node) {
              return node.id === '#' ? '/UserAccount/AccountGroupPermissions' 
                                     : '/UserAccount/AccountPermissions/' + node.id;
            },
            type: 'POST'
          }
       },
       plugins : ["checkbox"]
    });
    

提交回复
热议问题