问题
I want to keep my parent folder names uncheckable. but i can not pass the option with individual node here.
I wrote code like this.
$("#treeview-checkable").treeview({
data: root.attributeTopicList,
showIcon: true,
showCheckbox: true,
showBorder: false,
showTags: true,
});
};
回答1:
I had to Add some lines in bootstrapp-treeview.js file
Process-->>
Go inside bootstrapp_treeview.js
See how its render function works
- You will find that after treeview fire any event or make any changes on DOM it calls its render method
- You will find render method in line number 486
If you write your code in such way that your parent node should not have checkbox just write
for (var i = 0; i < $(".glyphicon-minus").length; i++) { $($(".glyphicon-minus")[i]).siblings(".check-icon").hide(); } for (i = 0; i < $(".glyphicon-plus").length; i++){ $($(".glyphicon-plus")[i]).siblings(".check-icon").hide(); }
回答2:
I encountered the same issue. In order to remove the checkbox from the upper most parent, I used a bit of a workaround.
After drawing the tree I tell it to find the data-nodeid=0 attribute and remove the check-icon classed span element.
So right after tree initializes I run this:
$("#treeview-checkable").find("[data-nodeid=0]").find(".check-icon").remove();
I also detected every click event on my page to do the same thing.
window.onclick = function(){
$("#treeview-checkable").find("[data-nodeid=0]").find(".check-icon").remove();
};
I do the same thing on every click because I found when I expanded, collapsed, did anything to the tree, the checkbox re-appeared.
Is this the best solution? No. Does it work? Yes.
来源:https://stackoverflow.com/questions/46339097/how-to-disable-parent-node-checkbox-of-bootstrap-treeview