I have working bootstrap treeview plugin. currently it works like, when user clicks on node once. it select the node. but if user click it again on same node. it deselect the node.
I am trying to change it like: if user clicks on node it select the node. until user clicks on any other node, but if user clicks on same node more than once. it should stay selected. it shouldn't be deselect.
I hope I have cleared enough my question.
https://jsfiddle.net/evk9yfum/
var initSelectableTree = function () {
return $('#treeview-selectable').treeview({
levels: 1,
data: defaultData,
enableLinks: true,
onNodeSelected: function (event, node) {
//$('.contanter').css('background','green');
},
onNodeUnselected: function (event, node) {
//$('.contanter').css('background','red');
}
});
};
var $selectableTree = initSelectableTree();
});
答案 0 :(得分:2)
以下代码段将为您解决问题。希望这会对你有所帮助。
var initSelectableTree = function () {
return $('#treeview-selectable').treeview({
levels: 1,
data: defaultData,
enableLinks: true,
onNodeSelected: function (event, node) {
$(this).treeview('unselectNode', [node.nodeId, { silent: false }]);
},
onNodeUnselected: function (event, node) {
$(this).treeview('selectNode', [node.nodeId, { silent: true }]);
},
onNodeCollapsed:function(event, node){
$.each(node.nodes, function(){
if(this.state.selected){
$('#treeview-selectable').treeview('selectNode',
[ node.nodeId, { silent: true } ]);
return;
}
});
}
});
};