问题描述
我有工作引导树视图。我想在此添加一个功能。
使用此 var slectedNodeId,hasSelect = false,nodeIdList = []
三个全局变量然后喜欢下面的代码。希望这会对你有所帮助。
onNodeExpanded:function(event,node){
$ .each(node.nodes) ,function(){
if((this.nodeId == slectedNodeId || nodeIdList.indexOf(this.nodeId)> -1)
&& hasSelect)
{
$('#treeview-selectable')。treeview('selectNode',
[this.nodeId,{silent:true}]);
}
});
},
onNodeCollapsed:function(event,node){
nodeIdList.push(node.nodeId);
$ .each(node.nodes,function(){
if(this.state.selected){
$('#treeview-selectable')。treeview('selectNode',
[nodeIdList [0],{silent:true}]);
hasSelect = true;
}
});
},
onNodeSelected:function(event,node){
slectedNodeId = node.nodeId;
nodeIdList = [];
hasSelect = false;
$(this).treeview('unselectNode',[node.nodeId,{silent:false}]);
},
onNodeUnselected:function(event,node){
$(this).treeview('selectNode',[node.nodeId,{silent:true}]);
}
更新小提琴:
I have working bootstrap tree view. I want add one feature in this.
https://jsfiddle.net/evk9yfum/
https://github.com/jonmiles/bootstrap-treeview (plugin used)
Eg: onNodeCollapsed: if collapsed node's child/grandChild already selected. then current collpased node should be shown as selected node.
Then on expand of this same node. it should show its/last selected or child/grandChild node.
onNodeCollapsed: function(event, node) {
$.each(node.nodes, function() {
if (this.state.selected) {
$('#treeview-selectable').treeview('selectNode', [node.nodeId, {
silent: true
}]);
return;
}
});
}
Use this var slectedNodeId, hasSelect=false, nodeIdList=[]
three global variable and then do like the code below. Hope this will help you.
onNodeExpanded:function(event, node){
$.each(node.nodes, function(){
if((this.nodeId==slectedNodeId || nodeIdList.indexOf(this.nodeId)>-1)
&& hasSelect)
{
$('#treeview-selectable').treeview('selectNode',
[ this.nodeId, { silent: true } ]);
}
});
},
onNodeCollapsed:function(event, node){
nodeIdList.push(node.nodeId);
$.each(node.nodes, function(){
if(this.state.selected){
$('#treeview-selectable').treeview('selectNode',
[nodeIdList[0], { silent: true } ]);
hasSelect=true;
}
});
},
onNodeSelected: function (event, node) {
slectedNodeId=node.nodeId;
nodeIdList=[];
hasSelect=false;
$(this).treeview('unselectNode', [ node.nodeId, { silent: false } ]);
},
onNodeUnselected: function (event, node) {
$(this).treeview('selectNode', [ node.nodeId, { silent: true } ]);
}
Updated Fiddle here: https://jsfiddle.net/evk9yfum/24/
这篇关于onCollapse将parent设置为选定节点,如果已选择子/孙(bootstrap treeView)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!