【问题标题】:Check one checkbox should not select the whole checkbox group选中一个复选框不应选择整个复选框组
【发布时间】:2017-05-05 19:17:33
【问题描述】:

以下是我用来填充复选框列表的代码。

<label class="checkbox-inline" ng-repeat="item in vm.ItemList track by item .id">
<input type="checkbox" name ="item " ng-value="item .id" ng-model ="vm.selecteditem" />{{item.name}}
</label>

上面的代码选择了ItemList中的所有项目。我只需要从 itemList 中选择一项。我该怎么做?

【问题讨论】:

  • 什么?............
  • 你有什么问题?
  • 请编辑您的问题

标签: angularjs typescript checkbox


【解决方案1】:

https://vitalets.github.io/checklist-model/

这个链接对我有用!

1) 设置 checklist-model 而不是 ng-model
2) 设置 checklist-value 而不是 ng-value

【讨论】:

    【解决方案2】:

    您将相同的外部化变量 vm.selectedItem 附加到每个复选框。因此,当您选中一个时,它会将该变量更改为true,然后选择所有复选框,因为它们绑定到同一个变量,现在是true。

    我对您的建议是将selected 属性附加到ItemList 中的每个项目。然后将其附加到 ng-model,如下所示。

    <label class="checkbox-inline" ng-repeat="item in vm.ItemList track by item .id">
         <input type="checkbox" name ="item " ng-value="item .id" ng-model= "item.selected" />{{item.name}}
    </label>
    

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 2012-12-22
      • 2012-05-08
      • 1970-01-01
      • 1970-01-01
      • 2015-01-24
      • 1970-01-01
      • 2015-06-06
      • 2017-08-10
      相关资源
      最近更新 更多