发布之前,我已经检查了关于stackoverflow的其他问题。一个是这样的:
但是以某种方式我无法使其正常运行。
我正在通过ajax获取子节点的详细信息。当您单击一个节点时,它将触发ajax请求并获取子节点详细信息。我想将这些详细信息附加到jstree中的parent(单击)节点上。
这是jsfiddle演示(不带ajax):https ://jsfiddle.net/8wyqd9om/
你能帮我吗?
HTML:
<div id='cat_tree'>
<ul>
<li id="1">First
<ul>
<li id="2">First</li>
<li id="3">First</li>
</ul>
</li>
<li id="4">First</li>
<li id="5">First</li>
<li id="6">First</li>
</ul>
</div>
js:
$(function () {
$('#cat_tree').jstree({"core": {
"themes":{
"icons":false
}
}});
var data = [
{ "id" : "7", "parent" : "#4", "text" : "second" },
{ "id" : "8", "parent" : "#4", "text" : "second" },
];
$('#click').click(function() {
$('#cat_tree').jstree().create_node($('#4'), data, 'last', function(){
alert("done");
}, true);
});
});
请检查以下代码
$(function() {
var data = [{
"id": "p1",
"parent": "#",
"text": "Parent-1"
}, {
"id": "p2",
"parent": "#",
"text": "Parent-2"
}, {
"id": "c1",
"parent": "p2",
"text": "Child 1"
}, {
"id": "c2",
"parent": "p2",
"text": "Child 2"
}, ];
$("#jstree").jstree({
"core": {
"check_callback": true,
"data": data
}
}).on('create_node.jstree', function(e, data) {
console.log('saved');
});
$('#btnCreate').click(function() {
$('#jstree').jstree().create_node('#', {
"id": "p3",
"text": "Parent-3"
}, "last", function() {
alert("Parent created");
});
$('#jstree').jstree().create_node('p2', {
"id": "c3",
"text": "Child 3"
}, "last", function() {
alert("Child created");
});
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句