且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jsTree:异步加载

更新时间:2023-12-05 08:51:52

我在jQuery的1.4此刻正在使用的这跟jsTree,这里是一个例子,这是pssed使它更清楚一点非常uncom $ P $

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");
    }
  }
});

JSON的样本,我从该URL返回:

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"
}]

的ID有获取传递给我的web服务方法回调,导致JSON这样返回的唯一的事:

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"
                }
            }
        }
    ]
}]