Javascript Jstree-单击父节点后加载子节点(json)
我想在单击父节点后加载父节点的子节点。 因为有很多孩子,这是保持高性能的唯一方法 现在我明白了Javascript Jstree-单击父节点后加载子节点(json),javascript,jquery,json,web,jstree,Javascript,Jquery,Json,Web,Jstree,我想在单击父节点后加载父节点的子节点。 因为有很多孩子,这是保持高性能的唯一方法 现在我明白了 $(function () { $.support.cors = true; $('#using_json').jstree({ "plugins": ["themes", "json_data", "dnd", "wholerow"], 'core': { 'data': { 'url':
$(function () {
$.support.cors = true;
$('#using_json').jstree({
"plugins": ["themes", "json_data", "dnd", "wholerow"],
'core': {
'data': {
'url': "http://localhost:56311/ProductRESTService.svc/GetCountryList",
'dataType': "json"
}
}
});
});
这对于第一个级别很有效。
现在我想从这个URL获取孩子们
“{id}”
我不知道如何才能做到这一点
编辑:
服务GetCountryList生成如下内容:
[{"id":"DE","parent":"#","state":"closed","text":"DE"},
{"id":"GBR","parent":"#","state":"closed","text":"GBR"},
{"id":"SE","parent":"#","state":"closed","text":"SE"}]
[{"id":"SH","parent":"DE","state":"closed","text":"SH"},
{"id":"NRW","parent":"DE","state":"closed","text":"NRW"},
{"id":"LON","parent":"GBR","state":"closed","text":"LON"}]
和GetRegionList
大概是这样的:
[{"id":"DE","parent":"#","state":"closed","text":"DE"},
{"id":"GBR","parent":"#","state":"closed","text":"GBR"},
{"id":"SE","parent":"#","state":"closed","text":"SE"}]
[{"id":"SH","parent":"DE","state":"closed","text":"SH"},
{"id":"NRW","parent":"DE","state":"closed","text":"NRW"},
{"id":"LON","parent":"GBR","state":"closed","text":"LON"}]
使用以下命令:
$(function () {
$.support.cors = true;
$('#using_json').jstree({
"plugins": ["themes", "json_data", "dnd", "wholerow"],
'core': {
'data': {
'url': function (node) {
if(node.id === '#') {
return "http://localhost:56311/ProductRESTService.svc/GetCountryList";
}
else {
return "http://localhost:56311/ProductRESTService.svc/GetRegionList/" + node.id;
}
},
'dataType': "json"
}
}
});
});
您正在谈论如何做:
var myid='123';变量url=”http://localhost:56311/ProductRESTService.svc/GetRegionList/“+myid
或者你能澄清一下你的问题吗?看看这里,我猜这就是你需要的。你好,谢谢你的帮助,我尝试了这个,然后得到了父节点,但是当我点击它们时没有发生任何事情。没有子节点。我在第一篇文章中编写了json文件。可能是错误。谢谢谢谢,这帮了大忙。当我将布尔参数子节点添加到节点时,效果很好。谢谢注意,在父节点上,第二次ajax调用需要使用children=true