使用动态值将Object转换为Array angularjs

时间:2016-12-27 11:31:47

标签: angularjs arrays angularjs-scope

{"13":"I","14":"E","15":"V","16":"G"}

为:

['I', 'E', 'V', 'G']

对象的0属性是否包含1和2个对象的数组?有没有办法做到这一点?

<div ng-repeat="data in data" >
<label>
<input ng-model="student[data.stn_id]"  ng-true-value="'{{data.stn_name}}'" ng-false-value="" /><span>{{data.stn_name}}</span>
                            </label>
                        </div>
                       {{student}}

由于

3 个答案:

答案 0 :(得分:1)

使用underscorejs

var d={"13":"I","14":"E","15":"V","16":"G"};
_.values(d);

答案 1 :(得分:0)

        var a = {"13":"I", "14":"E", "15":"V", "16":"G"};
        var b = [];
        angular.forEach(a, function(val, key){
          b.push(val);
        })
        console.log(b); // check the output ['I', 'E', 'V', 'G']

答案 2 :(得分:0)

var x = {"13":"I","14":"E","15":"V","16":"G"};

var result = [];
angular.forEach(x, function (value, key){
    result.push(value);
});

console.log(result); // [I,E,V,G]