ngOptions - 在表达式中使用track by时过滤器不起作用

时间:2017-01-19 05:17:57

标签: angularjs

请看这个plunker:https://plnkr.co/edit/U2oDUPl8w7lSlY8MkVLb?p=preview

为什么过滤器不能使用在表达式中具有track by的ng-options,并且在使用select as?

时工作
<span> state selector : </span>
<select ng-model="filter.stateID" 
      ng-options="item.stateID as item.state for item in st_option"></select>
<br>
<span>county selector: select as</span>
<select  
      ng-model="filter.countyID" 
      ng-options="item.countyID as item.county for item in co_option | filter:{ co_state_id : filter.stateID }">
</select>
<br>
<span>county selector: track by</span>
<select  
      ng-model="filter.countyID2" 
      ng-options="item.county for item in co_option track by item.countyID | filter:{ co_state_id : filter.stateID }">
</select>    

2 个答案:

答案 0 :(得分:2)

更改

ng-options="item.county for item in co_option track by item.countyID | filter:{ co_state_id : filter.stateID }">

ng-options="item.county for item in co_option | filter:{ co_state_id : filter.stateID } track by item.countyID">

答案 1 :(得分:2)

更改为:

<span>county selector: track by</span>
  <select ng-model="filter.countyID2" 
          ng-options="item.county for item in co_option | filter:{ co_state_id : filter.stateID } track by item.countyID">
  </select>