带对象的AngularJS数组
AngularJS array with Objects
我使用的是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"
所以我想做一个$scope。带有for循环的Planes数组。但是在第一个对象之后,它就不再填充了。我如何将其他对象推入数组?
谢谢
您需要实现push方法,$scope.planes。Push ('insert what you want Push here')
使用数组的push函数可以实现这一点。
$scope.planes=[];
for(var result in data)
{
$scope.planes.push({"planeLMID": data[result]['planeLMID']});
}
console.log($scope.planes);
你应该使用数组的.push()
方法
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);
$scope.planes = [];
for(var result in data)
{
$scope.planes.push({"planeLMID": data[result]['planeLMID']})
}
console.log($scope.planes);
});
};
$scope.createPlanes();
});
你可以这样做。
$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.push({
"planeLMID": data[result]['planeLMID']
});
}
console.log($scope.planes);
});
};
$scope.createPlanes();
相关文章:
- 如何将angularjs中的javascript字符串输出为循环数组
- angularjs$watch获取已更改数组项的索引
- AngularJS-ng使用字符串索引在数组上重复
- 如何使用angularJS从json的对象数组中显示和计数实体
- angularjs ng基于点击时的数组值重复过滤器
- 使用angularjs数组中的slice
- 从空格分隔的文本创建和实现数组:AngularJS
- json数组angularjs中的自定义过滤器
- 在方法中看不到对象数组.(Angularjs)
- 查找对象数组(Angularjs)中是否存在值
- $scope绑定到空值数组 AngularJs
- 同一数组(AngularJS)中的javascript对象之间的一对一关系
- 编译和传递数组 - AngularJS和PHP
- 如何根据数组AngularJS中的元素更改href
- 通过id过滤数组angularjs的数组
- 查找数组angularjs对象的索引
- 在数组angularjs javascript中选中或取消选中复选框
- 将JSON响应存储在数组angularjs中
- 如何将元素推送到指令中的数组 - AngularJS
- 动态追加值到数组angularjs