【发布时间】:2018-04-10 19:02:14
【问题描述】:
我有一个这样的选择元素
<select class="span3" ui-select2="{minimumResultsForSearch: -1}" ng-model="envelope.roofType">
<option value="">Select..</option>
<option ng-value="roof.id" ng-repeat="roof in roofList">{{roof.type}}</option>
</select>
所以基本上我在我的 post call 中发送与roofType 对应的 id。现在在我的 get 调用中我得到相同的 id。我在我的控制器中这样做。
$scope.envelope = success.records;
现在在我看来,由于 ng-model 对应于信封对象,envelope.roofType 显示的是 id 而不是实际类型。 我的问题是,有没有办法将这些 id 映射到应该显示的实际文本?
【问题讨论】:
-
将
envelope.roofType设置为 id 你得到了响应 -
通过这样做,id 将显示在选择选项而不是类型中
-
您的
ng-mode映射到$scope.envelope.roofType,因此在您的控制器中,您将获得分配给$scope.envelope.roofType的roof.id。
标签: angularjs angularjs-ng-repeat angularjs-ng-options ui-select2