ng模型内的ng重复的ng重复开始

ng model inside ng-repeat of ng-repeat-start

本文关键字:ng 开始 模型      更新时间:2023-09-26

我有以下结构,父级可以有多个子级,子级将有一个目标。我需要在可编辑的表中显示这一点,但当我将模型绑定到目标的输入中时,它也会更新所有其他选定的儿童目标。

这是代码

从两行的选项中选择相同的子项,并编辑其中一个子项的目标,它也将反映在另一行中。

<tbody>
        <tr ng-repeat-start="parent in records" ng-class-even="'striped'">
            <!--KPI-->
            <td><strong>{{parent.name}}</strong></td>
            <!-- controls -->
            <td tool-tips class="inputs">
                <select
                        ng-model="parent.childrens"
                        ng-options="item as item.name for item in controlTypes"
                        multiple='multiple'>
                </select>
            </td>
            <!-- Controls objective-->
            <td colspan="1"/>
            </td>
        </tr>
        <tr ng-if="parent.childrens.length>0"
            ng-repeat="child in parent.childrens">
            <td name="process" colspan="2" style="word-wrap:break-all;" align="right">{{child.name}}
            </td>
            <!-- Controls objective-->
            <td>
                <input type="text" class="ultra-short" ng-model="child.objective"
                       maxlength="200"/>
            </td>
        </tr>
        <tr ng-repeat-end></tr>
        </tbody>

请帮忙。

据我所知,它不适用于这样的结构,因为你所做的只是使用引用。当您更改某些选项objective属性时,实际上在同一选项中的任何位置都会更改它,因为您使用的是引用。

更新:
处理此的一种方法

如果您希望ng重复的每个迭代的模型都不同:

<div ng-repeat="parent in parents">
  <select
    ng-model="vm.model.parent.item"
    ng-options="item as item.name for item in controlTypes"
    multiple="multiple">
  </select>
</div>

现在每个迭代都有一个不同的模型,这就是你想要做的吗?