【发布时间】:2017-02-09 01:01:28
【问题描述】:
我正在使用 angularjs 框架。 这是我的代码:
var app = angular.module('app',['ngRoute','ngAnimate']);
app.controller('maincontroller',function($scope,$http) {
$scope.planes = [];
$scope.createPlanes = function() {
$http.post('api/create_plane.php',{
}).success(function(data,status,headers,config) {
console.log(data);
for(var result in data)
{
$scope.planes = [
{"planeLMID": data[result]['planeLMID']}
];
}
console.log($scope.planes);
});
};
$scope.createPlanes();
});
这就是console.log(data)的返回;
Object {1: Object, 2: Object, 3: Object, 4: Object, 5: Object, 6: Object, 7: Object, 8: Object, 9: Object, 14: Object, 15: Object, 16: Object, 17: Object, 18: Object, 20: Object, 21: Object, 23: Object, 24: Object, 25: Object, 26: Object, 27: Object, 29: Object, 31: Object, 32: Object, 33: Object, 34: Object, 35: Object, 36: Object, 37: Object, 38: Object}
以及其中一个对象的外观示例
planeAFID: "89-3412"
planeCPISPI: ""
planeLMID: "8215"
所以我想做一个带有 for 循环的 $scope.planes 数组。 但是在第一个对象之后它不再填充。如何将其他对象推入数组?
谢谢
【问题讨论】:
-
你可以做
$scope.planes.push( {"planeLMID": data[result]['planeLMID']}) -
天哪,对不起我的小失误。还是谢谢
标签: javascript php angularjs arrays