动态地如何根据存储在对象数组中的值将值设置为选择的angularjs中的选择下拉列表

时间:2016-10-06 19:07:21

标签: angularjs

I have multiple records which are stored in 

$ scope.myQuality

变量当前位于下面附加的plnkr中,但该数据将来自rest api。目前我已经使用ng-options显示我从$ scope.items获取的显示选项。根据(“status”:true)的值,我想将下拉值选为“OK”

如果

(“status”:true)

- >下拉列表中的选定值应该没问题

如果

(“status”:false)

- >下拉列表中的选定值应为KO

如果

  

(“status”:null)

- >下拉列表中的选定值应为空

每条记录都有下拉列表但是它的选择值会根据

中的状态值而有所不同
  

$ scope.myQuality

请找到以下网址

http://plnkr.co/edit/aW5enrHuEZ2jHiQuHQmV?p=preview

                                                                                                                                                             ID                                                                                                                                                                                                                                          日期                                                                                                                                                                                                   状态                                                                                                                                                           {{roll。 ID}}                                     {{roll。日期|日期:“dd / MM / yyyy HH:mm”}}                                                                                                                                                                                                                             

的script.js

  

//代码在这里

     

angular.module('sortApp',[])

     

.controller('mainController',function($ scope){       $ scope.sortType ='id'; //设置默认排序类型       $ scope.sortReverse = false; //设置默认排序顺序       $ scope.searchLists =''; //设置默认搜索/过滤条件

$scope.items =[
    {"value":true,"text":"OK"},
    {"value":false,"text":"KO"}
];

   $scope.myQuality = [
  {
            "id": 1,
            "status": true,
            "date": 1474864500000,
  }, {
            "id": 2,
            "status": false,
            "date": 1474741800000,
  },{
            "id": 3,
            "status": null,
            "date": 1474914600000,
  },{
            "id": 4,
            "status": true,
            "date": 1474914600000,
  },{
            "id": 5,  
             "status": true,
            "date": 1474914600000,
  },{
            "id": 6,  
             "status": true,
            "date": 1474914600000,
  },{
            "id": 7,  
            "status": true,
            "date": 1474914600000,
  },{
            "id": 8,  
             "status": true,
            "date": 1474914600000,
  },{
            "id": 9,  
            "status": true,
            "date": 1474914600000,
  },{
            "id": 10,  
            "status": false,
            "date": 1474914600000,
  },{
            "id": 11,  
             "status": true,
            "date": 1474914600000,
  },{
            "id": 12,  
            "status": false,
            "date": 1474914600000,
  }   ] });

1 个答案:

答案 0 :(得分:1)

只需从你的ng-options中删除曲目,下面是plnkr:

https://plnkr.co/edit/olbqvp2GiTTqr1JUyeSq?p=preview

ng-options="option.value as option.text for option in items"