下拉值在 nog 选项中复制 Angular
Drop down value replicates in nog options Angular
我有一个动态生成的 html table,它根据显示的记录添加行。我正在添加一个包含下拉列表的列。我为此使用了 ng-options,但是每次我更改一条记录时,其余记录也会更新。尝试将其更改为 ng-repeat 并获得相同的结果。请参阅下面的代码:
<td>
<select class="form-control" ng-model="$ctrl.selectedRC" ng- options="r.ccd as (r.OName + ' -- '+ r.RCName) for r in $ctrl.RC track by r.ccd"> </select>
<!--if I have 5 records, all dropdowns in the table change -->
</td>
使用 ng-repeat:
<select class="form-control" ng-model="$ctrl.selectedRC" <option value="" ng-selected="true">--Select one--</option>
<option ng-repeat="r in $ctrl.RC"
value="{{r.OName}}"
ng-selected="{{r.OName === selectedRC}}">{{r.RCName}}
</option>
</select>
我知道这两个目前正在显示两个不同的东西(一个是一组串联的值,另一个是一个)。但我的主要兴趣是弄清楚如何让每个 <td>
都有自己的下拉列表而不影响其余行。
仅仅是因为您对所有行使用相同的 ng-model。
您需要为每一行定义一个不同的行。
你这样做:
ng-model="$ctrl.selectedRC"
但是你需要这样的东西:
ng-model="$ctrl.selectedRC[$index]"
其中 $index 是您对该行的引用。
我有一个动态生成的 html table,它根据显示的记录添加行。我正在添加一个包含下拉列表的列。我为此使用了 ng-options,但是每次我更改一条记录时,其余记录也会更新。尝试将其更改为 ng-repeat 并获得相同的结果。请参阅下面的代码:
<td>
<select class="form-control" ng-model="$ctrl.selectedRC" ng- options="r.ccd as (r.OName + ' -- '+ r.RCName) for r in $ctrl.RC track by r.ccd"> </select>
<!--if I have 5 records, all dropdowns in the table change -->
</td>
使用 ng-repeat:
<select class="form-control" ng-model="$ctrl.selectedRC" <option value="" ng-selected="true">--Select one--</option>
<option ng-repeat="r in $ctrl.RC"
value="{{r.OName}}"
ng-selected="{{r.OName === selectedRC}}">{{r.RCName}}
</option>
</select>
我知道这两个目前正在显示两个不同的东西(一个是一组串联的值,另一个是一个)。但我的主要兴趣是弄清楚如何让每个 <td>
都有自己的下拉列表而不影响其余行。
仅仅是因为您对所有行使用相同的 ng-model。
您需要为每一行定义一个不同的行。
你这样做:
ng-model="$ctrl.selectedRC"
但是你需要这样的东西:
ng-model="$ctrl.selectedRC[$index]"
其中 $index 是您对该行的引用。