我定义了这个数组:
$scope.exportData = [];
然后我做一个api调用,它在我的数组中返回3个对象。
[Object, Object, Object] //from Console Log
0: Object
Name: "Steve"
Age: 30
Sex: "M"
1: Object
Name: "James"
Age: 25
Sex: "M"
2: Object
Name: "Joe"
Age: 20
Sex: "M"
我在这里要做的是获取$ scope.exportData中的对象并将它们转换为数组,因此我在$ scope.exportData中有5个数组,如下所示:
[Array[3], Array[3], Array[3]]
0: Array[3]
"Name" : "Steve"
"Age" : 30
"Sex" : "M"
1: Array[3]
"Name" : "James"
"Age" : 25
"Sex" : "M"
2: Array[3]
"Name" : "Joe"
"Age" : 20
"Sex" : "M"
我该怎么做?谢谢,任何帮助将不胜感激
答案 0 :(得分:2)
他们尝试这样,如果数据是对象数组,那么
for(var i = 0; i < $scope.exportData.length; i++) {
var arr = [];
for(j in $scope.exportData[i]) {
arr.push($scope.exportData[i][j]);
}
$scope.exportData[i] = arr;
}