假设我有一个REST,它让我回到了这个json格式:
{
"data": {
"result": [
{
"dispatch_type": "PDO",
"distribution_code": "foo"
},
{
"dispatch_type": "PNO",
"distribution_code": "foo"
}
]
},
"errors": []
}
并假设我想在以这种方式声明的select输入中添加所有dispatch_type:
<select ng-model="dispatchType"
ng-options="item as (item | uppercase) for item in searchFilterDispatcher.dispatchType"
class="form-control" id="dispatchType">
<option value="">*</option>
</select>
用这个js:
DispatcherFilterFactory.paramsMock().then(function(response) {
var result = response.data.result;
$scope.searchFilterDispatcher.dispatchType = result.dispatch_type ;
});
我应该如何设置将对象解析为数组的循环,以便我可以使用select?
答案 0 :(得分:1)
获取"dispatch_type"
DispatcherFilterFactory.paramsMock().then(function(response) {
var result = {};
result.dispatch_type = response.data.result.map(function (row) {
return row.dispatch_type;
});
$scope.searchFilterDispatcher.dispatchType = result.dispatch_type;
});