jstree树结构,每次加载完页面之后会把上一次的记录再次加载出来,
这种情况是不允许的,下面解决。看代码。data.instance.clear_state()
$('#jstree').jstree({
'core' : {
"multiple" : true,
"animation" : 0,
'data' : {
"url" : "",/*数据源*/
"dataType" : "json"
},
"themes" : {
"icons" : true/*图标显示开关*/
}
,"dblclick_toggle" : false,
"worker" : false
}
,"types": {
"default" : {
"icon": "fa fa-user"/*默认图标,也可以后台传icon属性放入map中,亲测有效*/
}
}
,'plugins' : ['types', 'wholerow','checkbox','state']
,"checkbox":{
"tie_selection":true,
"whole_node":true,
"keep_selected_style":false,
}
}).on('select_node.jstree',function(e,data){
debugger /*选中之后触发*/
}).on(' deselect_node.jstree',function(e,data){
debugger /*取消选中触发*/
}).on("loaded.jstree", function (event, data) {
/*这两句化是在loaded所有的树节点后,然后做的选中操作,这点是需要注意的,
loaded.jstree 这个函数取消选中,然后选中某一个节点*/
$('#jstree').jstree().open_all();/*打开树,不打开下面的选中语句执行有问题*/
var TempIds = $("#ids").val();
var TempIdsArr = TempIds.split(",");
data.instance.clear_state();/*此句用来清除之前选中的数据不可以去掉*/
$.each(TempIdsArr,function(index,value){
var id=value+'_anchor';
$('#jstree').jstree('select_node',id,true,true);/*选中id对应的节点*/
});
}).on("load_node.jstree",function(event,data){
debugger /*加载node时候触发*/
});