如何使 Repeater 中的下拉列表显示不同的值

How to make dropdown in Repeater display different values

我有一个 table,其中包含用户按下按钮添加的行。在此 table 中有一个显示值的下拉列表。我的问题是在一个下拉菜单中选择一些东西会改变所有这些。有人可以解释我做错了什么吗?

.HTML代码

<button ng-show="showAddChoice(choice)" ng-click="addNewChoice()">Add Entry</button>

<tbody data-ng-repeat="choice in choices">
  <tr>
      <td><input type="text" placeholder="Account Name" ng-model="item.AccountName" style="width:104px;"></td>
      <td><select ng-model="type.value" ng-options="v for v in type.values" style="width:80px"></select></td>
  </tr>
</tbody>

.JS 文件

 $scope.type = {
        "type": "select",
        "name": "Cash",
        "value": "Cash",
        "values": ["Cash", "Securities"]
    };

$scope.choices = [{ id: 'choice1' }];

    $scope.addNewChoice = function () {
        var newItemNo = $scope.choices.length + 1;
        $scope.choices.push({ 'id': 'choice' + newItemNo });
    };

    $scope.showAddChoice = function (choice) {
        return choice.id === $scope.choices[$scope.choices.length - 1].id;
    };

您已在循环中将相同的 ng-model 分配给 select。全部指向同一个变量。ng-model="type.value"

您可以使用 choise.type_value 作为示例,而不是将相同的值绑定到所有。这会将每个选择的值存储在其自己的变量中。