如何使用数据变量加载 jsTree

发布于 2024-11-19 02:07:39 字数 2034 浏览 6 评论 0原文

我对 wcf 模块进行了 ajax 调用,该模块返回这种格式的菜单树。 (截断)

    { "data" : [
          {
          "data" : "Home", 
          "attr" : {"webpageid" : "1", "url"     : "/Intranet/index.html", "appcode" : "Intranet Home", "parent"  : "0", "enabled" : "1", "visible" : "1", "target"  : "_self     ", "order"   : "0", "title"   : "Home", "itmname" : "index", "submenuclass" : "", "htmlid" : "homenav", "opennewtab" : "true", "externalsite" : "0"},
          "children" :[
                        {
                        "data" : "Site Administration", 
                        "attr" : {"webpageid" : "64", "url"     : "", "appcode" : "Mgmt/S0001", "parent"  : "1", "enabled" : "1", "visible" : "1", "target"  : "_self     ", "order"   : "1", "title"   : "Site Administration", "itmname" : "SiteAdmin", "submenuclass" : "", "htmlid" : "", "opennewtab" : "false", "externalsite" : "0"},
                        "children" :[
                        {
                        "data" : "Add Web Page", 
                        "attr" : {"webpageid" : "65", "url"     : "/Intranet/admin/mgmt/addwebpage.html", "appcode" : "Mgmt/S0002", "parent"  : "64", "enabled" : "1", "visible" : "1", "target"  : "_self     ", "order"   : "1", "title"   : "Add Web Page", "itmname" : "AddPage", "submenuclass" : "", "htmlid" : "", "opennewtab" : "false", "externalsite" : "0"} 
                        }
                      ]
          }
        ]

},...更多数据... ]}

这是我的 ajax 调用的回调函数:

function fSucc(data) {
    $(function () {
        $('#webpagetree').jstree({
            "json_data": (function () { return data; })(),
            "ui": { "select_limit": 1 },
            "plugins": ["themes", "json_data", "ui", "themeroller", "dnd", "crrm"]
        }).bind("select_node.jstree", function (e, data) {
            alert(jQuery.data(data.rslt.obj[0], "jstree").id)
        });
    });
}

但它不会创建或加载 jsTree 的实例。

相反,我收到错误“既没有提供数据,也没有提供 ajax 设置。” 我还尝试将数据放入全局变量中,然后返回。

感谢您的帮助

I have an ajax call to a wcf module that returns a menu tree in this format. (truncated)

    { "data" : [
          {
          "data" : "Home", 
          "attr" : {"webpageid" : "1", "url"     : "/Intranet/index.html", "appcode" : "Intranet Home", "parent"  : "0", "enabled" : "1", "visible" : "1", "target"  : "_self     ", "order"   : "0", "title"   : "Home", "itmname" : "index", "submenuclass" : "", "htmlid" : "homenav", "opennewtab" : "true", "externalsite" : "0"},
          "children" :[
                        {
                        "data" : "Site Administration", 
                        "attr" : {"webpageid" : "64", "url"     : "", "appcode" : "Mgmt/S0001", "parent"  : "1", "enabled" : "1", "visible" : "1", "target"  : "_self     ", "order"   : "1", "title"   : "Site Administration", "itmname" : "SiteAdmin", "submenuclass" : "", "htmlid" : "", "opennewtab" : "false", "externalsite" : "0"},
                        "children" :[
                        {
                        "data" : "Add Web Page", 
                        "attr" : {"webpageid" : "65", "url"     : "/Intranet/admin/mgmt/addwebpage.html", "appcode" : "Mgmt/S0002", "parent"  : "64", "enabled" : "1", "visible" : "1", "target"  : "_self     ", "order"   : "1", "title"   : "Add Web Page", "itmname" : "AddPage", "submenuclass" : "", "htmlid" : "", "opennewtab" : "false", "externalsite" : "0"} 
                        }
                      ]
          }
        ]

}, ... more data ...
]}

here is the call back function from my ajax call:

function fSucc(data) {
    $(function () {
        $('#webpagetree').jstree({
            "json_data": (function () { return data; })(),
            "ui": { "select_limit": 1 },
            "plugins": ["themes", "json_data", "ui", "themeroller", "dnd", "crrm"]
        }).bind("select_node.jstree", function (e, data) {
            alert(jQuery.data(data.rslt.obj[0], "jstree").id)
        });
    });
}

but it doesn't create or load an instance of the jsTree.

instead I get the error "Neither data nor ajax settings supplied."
I've also tried putting the data into a global variable, then returning that.

Thanks for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

剑心龙吟 2024-11-26 02:07:39

您不想只

$('#webpagetree').jstree({
    "json_data": data,
...

在 fSucc 函数中吗?

Wouldn't you just want

$('#webpagetree').jstree({
    "json_data": data,
...

in your fSucc function?

漫雪独思 2024-11-26 02:07:39

在数据周围添加一个 eval() 就可以了。

"json_data": { "data" : eval(data) },

Adding an eval() around the data will work.

"json_data": { "data" : eval(data) },
枉心 2024-11-26 02:07:39

通过在函数 eval() 中传递包含 json 的变量,效果很好:

$('#webpagetree').jstree({
    'core': {
        'data': eval(myJson)
    }
});

It works well by passing the variable containing the json in the function eval() :

$('#webpagetree').jstree({
    'core': {
        'data': eval(myJson)
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文