在ng-repeat of ng-repeat-start中的ng模型

时间:2016-05-14 06:38:41

标签: javascript angularjs

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

这里是 code

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

<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>

请帮助。

2 个答案:

答案 0 :(得分:1)

据我所知,它可以使用这种结构,因为你所做的就是使用引用。当您更改某些选项objective属性时,您实际上会在同一选项中的任何位置更改它,因为您正在使用引用。

<强>更新
One way来处理这个

答案 1 :(得分:0)

如果您希望模型在ng-repeat的每次迭代中都不同:

<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>

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

相关问题