两个匹配选择'值

时间:2015-10-21 13:36:31

标签: javascript angularjs

我有两个选择镜像相同的复合值 - 改变一个应该改变另一个:

<div class="form-group">
     <label for="type" class="control-label col-sm-2">First:</label>
         <div class="col-sm-7">
              <select name="general[first]" id="first" class="chosen-select-no-single"
                      data-placeholder="Choose first"
                      chosen="dataArray"
                      ng-options="row as row.first for row in dataArray"
                      ng-model="selectedItem"
                      ng-check="selectedItem"
                      style="width: 100%;">
               </select>
          </div>
</div>
<div class="form-group">
    <label for="type" class="control-label col-sm-2">Second:</label>
         <div class="col-sm-7">
              <select name="general[second]" id="second" class="chosen-select-no-single"
                      data-placeholder="Choose second"
                      chosen="dataArray"
                      ng-options="row as row.second for row in dataArray"
                            ng-model="selectedItem"
                            ng-change="update()"
                            ng-check="selectedItem"
                            style="width: 100%;">
               </select>
          </div>
</div>

它有效,但值不正确。我希望值为row.firstrow.second,而现在它是object:8object:6

我尝试将ng-options设置为row.first as row.first,但这样选择不匹配 - 更改第一个不会更改第二个。

怎么了?

1 个答案:

答案 0 :(得分:0)

答案是使用track by,如下所示:

ng-options="row as row.second for row in dataArray track by row.second"

通过这种方式,我可以根据需要实现多个选择和值的值匹配。