【发布时间】:2018-12-21 23:35:06
【问题描述】:
我在 AngularJS 中有一个清单模型表单(多个复选框),需要从数组中读取/添加/删除值。该数组可能没有值,也可能有五个值。数组值为 20、21、22、23、24。每个值对应于五个复选框。如果数组包含“20”,则将检查“20”的复选框输入,等等...
如果我使用 ng-model 而不是 checklist-model,它可以工作。该复选框在加载表单时被选中,因为 formData.observations == 20。当我取消选中框 20 时,会按预期从 formData.observations 数组中删除。
当我使用 checklist-model 时,复选框未被选中,并且单击该框永远不会删除或将值添加到 formData.observations 数组中。
[...html]
<div class="row">
<div class="col-md-1 col-sm-1 col-xs-1">
<input id="observation" type="checkbox" checklist-model="formData.observations" checklist-value="formData.observations[20]" ng-true-value="[20]" ng-false-value="[]">
<label for="smelled_observation"></label>
</div>
<div class="col-md-10 col-md-10 col-xs-10">
<label class="filter-label" for="observation">Confirmed</label>
</div>
</div>
[...service]
formData = {
version: 1,
observation: [20],
actionsTaken: [],
additionalNotes: 'notes...',
userName: 'John Doe',
timestamp: 'ISO8061',
}
当表单加载时,复选框应该被“选中”,因为 formData.observations = 20(这在使用 ng-model 时有效)。
【问题讨论】:
标签: angularjs checkbox checklist-model