jsTree: async loading

前端 未结 1 831
鱼传尺愫
鱼传尺愫 2021-02-15 12:40

I am trying to use this jQuery plugin (jsTree) in one of my project.
All the others I\'ve found haven\'t been recently updated.
Anyway, I am using this plugin to lo

相关标签:
1条回答
  • 2021-02-15 13:08

    I'm using this with jsTree in jQuery 1.4 at the moment, here's an example, it's very uncompressed to make it a bit clearer:

    $("#QuickNav").tree({
      data: {
        async: true,
        type: "json",
        opts: {
          method: "POST",
          url: rootPath + "QuickNav"
        }
      },
      callback: {
        beforedata: function(NODE, TREE_OBJ) {
          return $(NODE).attr("id") === "" ?
           { id: $(NODE).find("a:first").attr("id")} :
           { id: $(NODE).attr("id") || 0 };
        },
        onchange: function(NODE) {
          document.location.href = $(NODE).children("a:first").attr("href");
        }
      }
    });
    

    A sample of JSON I'm returning from that Url:

    [{
        "data": {
            "title": "Title (<b link='/Thing/200' class='gtp'>Go to Page</b>)",
            "attributes": {
                "href": "#",
                "id": "200"
            }
        },
        "state": "closed"
    }]
    

    The id there is the only thing that gets passed to my web service method callbacks, resulting in JSON like this being returned:

    [{
        "data": {
            "title": "Sites",
            "attributes": {
                "href": "#",
                "class": "TreeTitle"
            }
        },
        "state": "open",
        "children": [
            {
                "data": {
                    "title": "00001 - Test Thing",
                    "type": "link",
                    "attributes": {
                        "href": "/Site/39063",
                        "class": "TL"
                    }
                }
            },
            {
                "data": {
                    "title": "00002 - Test Thing 2",
                    "type": "link",
                    "attributes": {
                        "href": "/Site/39069",
                        "class": "TL"
                    }
                }
            }
        ]
    }]
    
    0 讨论(0)
提交回复
热议问题