更改 jstree 中的 AJAX 选项并从服务器重新加载树
我正在使用 ajax 在 jsTree 中加载 XML 平面树,因此声明如下所示(工作正常):
$("#jstree").jstree({
"xml_data": {
// "data": $xmlFlatData,
"ajax": {
type: "POST",
async: true,
"url": loc + "/AjaxReturnTree",
data: '{"longnames":"'+flag+'"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (msg) {
var mm = eval('(' + msg + ')'); ; // create object to get rid of json
return mm.d;
},
error: function () {
// TODO process error
}
},
"xsl": "flat",
"override_ui": "true",
"real_checkboxes": "true"
},
"plugins": ["xml_data", "themes", "checkbox", "ui"]
});
现在我需要重新加载树并将“longnames”部分更改为另一个标志(它是 0/1),但是其他选项保持不变。
我正在尝试使用这样的东西:
$("#jstree").jstree({
"xml_data": {
"ajax": {
cache: false,
data: '{"longnames":"' + flag + '"}'
}
}
});
$("#jstree").jstree("refresh");
但它不会触发新的 AJAX 请求,只会刷新屏幕上的树而不重新加载。
如何从服务器重新加载树?
另外,我如何确定我更改了旧ajax设置的属性,而不是创建一个全新的树对象?
I am loading XML flat tree in my jsTree using ajax, so the declaration looks like this (it works fine):
$("#jstree").jstree({
"xml_data": {
// "data": $xmlFlatData,
"ajax": {
type: "POST",
async: true,
"url": loc + "/AjaxReturnTree",
data: '{"longnames":"'+flag+'"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (msg) {
var mm = eval('(' + msg + ')'); ; // create object to get rid of json
return mm.d;
},
error: function () {
// TODO process error
}
},
"xsl": "flat",
"override_ui": "true",
"real_checkboxes": "true"
},
"plugins": ["xml_data", "themes", "checkbox", "ui"]
});
Now I need to reload the tree AND change the "longnames" part to another flag (it's either 0/1), but keep other options unchanged.
I am trying to use something like this:
$("#jstree").jstree({
"xml_data": {
"ajax": {
cache: false,
data: '{"longnames":"' + flag + '"}'
}
}
});
$("#jstree").jstree("refresh");
But it does not trigger new AJAX request, only refreshes the tree on screen without reload.
How I can get tree to reload from server?
Also, how I can be sure that I change properties of old ajax setup, not creating a completely new tree object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应删除“data:getData”的括号
或者,jQuery 将执行 getData() 并仅保留第一次执行的结果。
如果没有括号,jQuery 会将“数据”的值作为函数进行交易并每次都运行它。
顺便说一句,请注意“cache: false”,jQuery 将发布“_”cacheBurster。
should remove parentheses of "data:getData"
Or, jQuery will execute getData() and keep only the result from first execution.
Without parentheses, jQuery will trade the value of "data" as a function and run it every time.
BTW, beware the "cache: false", jQuery will post "_" cacheBurster.