jsTree:异步加载 [英] jsTree: async loading

查看:474
本文介绍了jsTree:异步加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的项目之一,使用这个jQuery插件(jsTree)。

所有的人,我发现最近没有更新。

总之,我使用这个插件加载一个文件夹结构,但我想这样做
操作异步。
我已经在其网站上(称为异步)中发现的例子是可笑的。
我试着在网上查,但似乎大多数人都加载整个树。
我想加载在每一个节点的点击一个分支。
我使用JSON。

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 load a folder structure, but I would like to do this operation async. The examples I've found on their site (called async) are ridiculous. I've tried to check on the Internet but it seems that most people load the whole tree. I would like to load a branch on every single node click. I am using JSON.

感谢提前

推荐答案

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

这篇关于jsTree:异步加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆