我正在给我的树做Json文件,它看起来就像
root > parent1 > parent > child1 : child2 : child3 : etc我添加了eventHandler,对于一些孩子,通过单击,我得到了一些东西,如表、信息等等。问题是,当我单击child1时,我想从其他json文件中再添加一个树分支。我以jsTree文档为例
$('#tree').jstree({
'core' : {
'data' : {
'url' : function (node) {
return node.id === '#' ?
'ajax_roots.json' :
'ajax_children.json';
},
'data' : function (node) {
return { 'id' : node.id };
}
}
});把它设置成我的代码..。
var $industry = $('#industry');
$industry.jstree({
"core" : {
"animation" : 0,
"check_callback" : true,
"themes" : {
"dot": true,
"stripes" : true,
"responsive": false
},
'data' : {
'url' : function (node) {
return node.id === '#' ?
'data/industry.json' :
'data/SDTM.json';
},
'data' : function (node) {
return { 'id' : node.id };
}
}
}});然后我在子上添加了eventHandler,我想要合并它
// ===== Click event on node =====
for(var i = 0; i < data.selected.length; i++) {
var node = data.instance.get_node(data.selected[i]).text;
if (node == "SDTM 3.1.1"){
//console.log(node);
$.jstree._reference($industry)
.create_node(
'select_node.jstree', 'after',
{ state: 'open', data: 'data/SDTM.json' }
); }
}
})
.jstree();在控制台,我会得到下一个错误
Uncaught TypeError: $.jstree._reference is not a function我做错什么了?
发布于 2016-02-29 18:53:09
我会这样做:
for (var i = 0; i < data.selected.length; i++) {
var node = data.instance.get_node(data.selected[i]),
nodeText = node.text;
if (nodeText == "SDTM 3.1.1") {
//console.log(node);
// get data for the branch, need to write code here
var branchJson = ... data/SDTM.json
/*
branchJson should contain an array of objects,
each object may have keys like below
{
text : 'Node text'
children : [...],
state : { 'open' }
}
*/
// iterate nodes in received json
branchJson.forEach( function(obj) {
data.instance.create_node( node, obj, 'after' );
})
}
}https://stackoverflow.com/questions/35705806
复制相似问题