最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to disable parent node checkbox of Bootstrap Treeview - Stack Overflow

programmeradmin2浏览0评论

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,
    });

};

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,
    });

};
Share Improve this question edited Sep 21, 2017 at 8:34 Nope 22.3k8 gold badges49 silver badges73 bronze badges asked Sep 21, 2017 at 8:32 Habibul HasanHabibul Hasan 1031 silver badge14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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();
        }
    

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.

发布评论

评论列表(0)

  1. 暂无评论