8

我正在尝试在我的一个项目中使用这个 jQuery 插件(jsTree)。
我发现的所有其他内容最近都没有更新。
无论如何,我正在使用这个插件来加载文件夹结构,但我想异步执行此操作。我在他们的网站上找到的示例(称为异步)很荒谬。我曾尝试在 Internet 上进行检查,但似乎大多数人都加载了整棵树。我想在每个节点单击时加载一个分支。我正在使用 JSON。

预先感谢

4

1 回答 1

8

我目前在 jQuery 1.4 中将它与 jsTree 一起使用,这是一个示例,它非常未压缩以使其更清晰:

$("#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 示例:

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

那里的 id 是唯一传递给我的 Web 服务方法回调的东西,导致返回这样的 JSON:

[{
    "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"
                }
            }
        }
    ]
}]
于 2010-03-11T18:49:05.383 回答