如果函数与调用者不在同一文档中,则将 JStree 包裹在函数中并传递变量将不起作用
如果我的 JStree 初始化函数与调用者位于同一文件中,则一切正常,但如果我将函数调用移动到 html 文档,它不会返回任何内容。这是我现在想到的代码:
function cattree(treeID, treeAncestors, treeCurrent) {
alert(treeID + treeAncestors + treeCurrent);
$("#"+treeID).jstree({
"core" : {
"initially_load" : treeAncestors,
},
"ui" :{
"select_limit" : 1,
"initially_select" : [treeCurrent],
},
"json_data" : {
"progressive_render" : true,
"progressive_unload" : true,
"ajax" : {
"url" : "/taxonomy/catjson",
"dataType": "text json",
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
}
}
},
"plugins" : [ "themes", "json_data", "ui" ],
});
}
当我将其移动到文档时,我认为它不会等待具有功能的文档加载。
$(document).ready(function(){
cattree("demo", ['4e974c91f0282e7011000004', '4e974d92f0282ec41a00000a'], ['4e974da1f0282e2c0c000000']);
}
);
If my JStree initialisation function is in the same file as caller everything works, but if I move function call to html document it does not return anything. Here is the code I came up up to now:
function cattree(treeID, treeAncestors, treeCurrent) {
alert(treeID + treeAncestors + treeCurrent);
$("#"+treeID).jstree({
"core" : {
"initially_load" : treeAncestors,
},
"ui" :{
"select_limit" : 1,
"initially_select" : [treeCurrent],
},
"json_data" : {
"progressive_render" : true,
"progressive_unload" : true,
"ajax" : {
"url" : "/taxonomy/catjson",
"dataType": "text json",
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
}
}
},
"plugins" : [ "themes", "json_data", "ui" ],
});
}
When I move it to document I think it does not wait for document with function to load.
$(document).ready(function(){
cattree("demo", ['4e974c91f0282e7011000004', '4e974d92f0282ec41a00000a'], ['4e974da1f0282e2c0c000000']);
}
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是想出来的:
外部文件中的 cattree init
以及 head 部分中的代码或我认为位于所有 html 之下:
目前它工作得很好。我认为问题在于该函数在加载所有内容之前被调用。与之前将 Jquery.cattree 添加到 if 语句一样,它无法将 $.cattree 识别为函数。
Here is what came up with:
cattree init in external file
And the code in head section or I think below all html:
At the moment it works quite nicely. And I think the issue was that the function was called before everything is loaded. As before adding Jquery.cattree to if statement it was failing to recognize $.cattree as a function.