如何使用数据变量加载 jsTree
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不想只
在 fSucc 函数中吗?
Wouldn't you just want
in your fSucc function?
在数据周围添加一个 eval() 就可以了。
Adding an eval() around the data will work.
通过在函数 eval() 中传递包含 json 的变量,效果很好:
It works well by passing the variable containing the json in the function eval() :