Treeview复选框充当radiobutton

时间:2018-04-30 05:45:56

标签: angularjs checkbox kendo-ui radio-button treeview

示例图:

enter image description here

我希望这个特定的节点组充当radiobutton(只应检查1个)。我知道我可以通过硬编码条件处理这个问题,但是我希望通过更改其json列' Group'来使其在未来可扩展(添加更多复选框)。

示例数据:

                      [
                        { id:"1", text: "Items", expanded: true, List: [
                            { id:"2",text: "book" ,group: 1},//group for radiobutton actions
                            { id:"3",text: "chair",group: 1 },
                            { id:"4",text: "table",group: 1 },
                            { id:"5",text: "mat", group: 0 },
                            { id:"6",text: "decor", group: 0}
                        ] }
                      ]

我发现这个jsfiddle关于引用的组属性的例子。

1 个答案:

答案 0 :(得分:0)

这是最好的(我认为)这样做的方法:

<强> 1。声明要分组的ID w / c数组:

var group = ["2","3","4"]; //in my example above

<强> 2。在check活动中:

 if (group.indexOf(dataItem.ID) > -1) { //if the ID you clicked exists in the group
       group.splice(group.indexOf(dataItem.ID), 1); //remove the ID from the group
       for (var i = 0, j = treeview.length; i < j; i++) {
           for (var x = 0, y = treeview[i].List.length; x < y; x++) {
               if (group.indexOf(treeview[i].List[x].ID) > -1) { 
                   treeview[i].List[x].set("checked", false); //uncheck the members of the group
               }
           }
       }
   }