【问题标题】:Treeview checkbox act as radiobutton树视图复选框充当单选按钮
【发布时间】:2018-10-10 04:47:22
【问题描述】:

示例图:

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

样本数据:

                      [
                        { 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 示例,关于引用的组属性。

【问题讨论】:

  • 无论如何您都必须对其进行编码,问题是如何使其可重用。我建议为您的树视图创建一个 wrapper 以防您在自己制作的小部件中进行任何其他自定义;或者只是创建一个函数来处理它,这样您就可以在需要时调用它。
  • @DontVoteMeDown 我想我可以使用 node.find by 'group: 1' 然后将其设置为 false。这可能吗?
  • @DontVoteMeDown 你能把你的进程的sn-p吗?我现在至少需要创建一个功能代码,然后再缩短。

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


【解决方案1】:

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

1.声明要分组的 ID 数组:

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
               }
           }
       }
   }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多