gpt4 book ai didi

jstree - jsTree如何更改Ajax网址并重新加载数据

转载 作者:行者123 更新时间:2023-12-04 17:18:48 29 4
gpt4 key购买 nike

    $('#jstree_demo_div2').jstree({
'core': {
'data': {
"url": "tree.ashx?id=" + _id,
"dataType": "json" // needed only if you do not supply JSON headers
}
},
"checkbox": {
'visible': true,
'keep_selected_style': false,
},
"plugins": ["wholerow", "checkbox"]
});

我需要更改url(否则变量 _id将更改),然后刷新数据。
但是似乎有一个缓存问题。

我监视了HTTP请求,请求参数 _id保持不变。

我试过了
'core': {
'data': {
"url": "tree.ashx?id=" + _id,
"cache":false, //←←←←
"dataType": "json" // needed only if you do not supply JSON headers
}
},

而且没有用。

顺便说一句,我的jsTree.js版本是3.0.8。

最佳答案

我正在使用以下代码来测试您的用例。它在刷新jstree而不折叠整个树的情况下。

<!DOCTYPE html>

<html>
<head>
<title>JSTree</title>
<link rel="stylesheet" href="dist/themes/default/style.css" />
<script src="dist/libs/jquery.js"></script>
<script src="dist/jstree.js"></script>
<script>
var arrayCollection;
$(function() {
arrayCollection = [
{"id": "animal", "parent": "#", "text": "Animals"},
{"id": "device", "parent": "#", "text": "Devices"},
{"id": "dog", "parent": "animal", "text": "Dogs"},
{"id": "lion", "parent": "animal", "text": "Lions"},
{"id": "mobile", "parent": "device", "text": "Mobile Phones"},
{"id": "lappy", "parent": "device", "text": "Laptops"},
{"id": "daburman", "parent": "dog", "text": "Dabur Man", "icon": "/"},
{"id": "dalmatian", "parent": "dog", "text": "Dalmatian", "icon": "/"},
{"id": "african", "parent": "lion", "text": "African Lion", "icon": "/"},
{"id": "indian", "parent": "lion", "text": "Indian Lion", "icon": "/"},
{"id": "apple", "parent": "mobile", "text": "Apple IPhone 6", "icon": "/"},
{"id": "samsung", "parent": "mobile", "text": "Samsung Note II", "icon": "/"},
{"id": "lenevo", "parent": "lappy", "text": "Lenevo", "icon": "/"},
{"id": "hp", "parent": "lappy", "text": "HP", "icon": "/"}
];
$('#jstree').jstree({
'core': {
'data': arrayCollection
},
"checkbox": {
'visible': true,
'keep_selected_style': false
},
"plugins": ["wholerow", "checkbox"]
});
});
function resfreshJSTree() {
$('#jstree').jstree(true).settings.core.data = arrayCollection;
$('#jstree').jstree(true).refresh();
}
function addNokia() {
var nokia = {"id": "nokia", "parent": "mobile", "text": "Nokia Lumia", "icon": "/"};
arrayCollection.push(nokia);
resfreshJSTree();
}
function deleteDalmatian() {
arrayCollection = arrayCollection
.filter(function(el) {
return el.id !== "dalmatian";
});
resfreshJSTree();
}
</script>
</head>
<body>
<input type="button" onclick="addNokia()" value="Add Nokia"/>
<input type="button" onclick="deleteDalmatian()" value="Delete Dalmatian"/>
<div id="jstree"></div>
</body>
</html>
  • 注意:
  • 在浏览器中打开上述页面后,打开jstree的所有节点和子节点。
  • 单击添加诺基亚按钮。
  • 它将诺基亚诺基亚Lumia节点添加到“手机”节点而不会崩溃
    树到根节点。
  • 同样,单击“删除Dalmaitian”按钮。
  • 它将从Dogs节点中删除Dalmatian节点并刷新
    树以显示新结构而不折叠到根节点。
  • 关于jstree - jsTree如何更改Ajax网址并重新加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26731955/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com