Angular.js 在 ng-repeat 中设置 ng-options

Angular.js setting ng-options with in ng-repeat

我正在尝试根据 ng-repeat 中的值设置正确的 select 选项。

参见此处示例:https://jsfiddle.net/vok080z4/5/

疯了,如果你看例子,为什么dave设置为苹果,而其他人没有?

<body ng-app="eApp">
  <div ng-controller="splitsController" ng-cloak>

    <table class="widefat fixed" cellspacing="0">
      <thead class="thead">
        <tr>
          <th>Name</th>
          <th>Fruit</th>
       </tr>
      </thead>
      <tbody class="tbody">
        <tr ng-repeat="order in data.orders" ng-class-odd="'alternate'">
          <td>{{order.name}}</td>
          <td>
            <select ng-model="fruitSelect">
              <option value="">-- Select One --</option>
              <option ng-repeat="fruit in data.fruits track by fruit.id" value="{{fruit.id}}" ng-selected="fruit.id === order.fruitId">
                {{fruit.name}}
              </option>
            </select>
          </td>
         <td>
       </tr>
     </tbody>
   </table>
 </div>
</body>

您应该使用 ngOptions to generate select options and more important use ngModel 来保留选定的值。

<select ng-model="order.fruitId" ng-options="item.id as item.name for item in data.fruits">
      <option value="">-- Select One --</option>              
</select>

DEMO