【发布时间】:2014-06-07 03:14:38
【问题描述】:
这应该很简单。出于某种原因,当在 ng-repeat 中使用 ng-model 时,它会更新该重复循环内的所有 ng-model。
这是代码。有任何想法吗? http://plnkr.co/edit/iAgrPwwBMilCyeReeLt9?p=info
谢谢。
【问题讨论】:
标签: angularjs angularjs-ng-repeat ng-repeat angular-ngmodel
这应该很简单。出于某种原因,当在 ng-repeat 中使用 ng-model 时,它会更新该重复循环内的所有 ng-model。
这是代码。有任何想法吗? http://plnkr.co/edit/iAgrPwwBMilCyeReeLt9?p=info
谢谢。
【问题讨论】:
标签: angularjs angularjs-ng-repeat ng-repeat angular-ngmodel
有趣!!!
问题是您正在使用“$scope.columns”中的对象重置 row.field
在
<td>
<select ng-model="row.field" ng-options="column.title for column in columns"></select>
</td>
在这里,row.field 使用 $scope.columns 中的对象重置,如果您在一行中更改此对象,因为其他行也使用相同的对象,它们会重复相同的值。
您可以将此模型更改为 row.field.type 为
<td>
<select ng-model="row.field.type" ng-options="column.type as column.title for column in columns" ng-change="resetRow(row.field)"></select>
</td>
并在控制器中定义 $scope.resetRow 以根据字段类型重置其他属性。
这是更新后的plunker。
我希望在 ng-options 中有一个功能来返回 选择对象而不是对象引用来解决您的问题。
【讨论】: