gpt4 book ai didi

javascript - AngularJS 数组分割

转载 作者:行者123 更新时间:2023-11-28 05:25:37 25 4
gpt4 key购买 nike

我对 AngularJS 比较陌生。我通过 $http.get 请求从 java spring 获取数据,格式如下:

[
{
"obj1": 1039751,
"obj2": "ABC",
"obj3": "INDIA",
"obj4": 57,
"obj5": 16,
"obj6": 43
},
{
"obj1": 895321,
"obj2": "PQR",
"obj3": "AUSTRALIA",
"obj4": 86,
"obj5": 43,
"obj6": 24
},
{
"obj1": 926384,
"obj2": "MNO",
"obj3": "DUBAI",
"obj4": 16,
"obj5": 12,
"obj6": 76
},
{
"obj1": 837537,
"obj2": "LMN",
"obj3": "ENGLAND",
"obj4": 83,
"obj5": 15,
"obj6": 43
},
{
"obj1": 867152,
"obj2": "JKL",
"obj3": "JAPAN",
"obj4": 49,
"obj5": 76,
"obj6": 16
},
{
"obj1": 1003783,
"obj2": "XYZ",
"obj3": "BHUTAN",
"obj4": 16,
"obj5": 42,
"obj6": 94
},
{
"obj1": 864287,
"obj2": "DEF",
"obj3": "USA",
"obj4": 96,
"obj5": 16,
"obj6": 37
}
]

<小时/>我的 app.js:

var app = angular.module("myApp", ['smart-table']);
app.controller("ctrl", function($scope, $rootScope, $timeout, $http) {
init();

function init() {
$scope.rowCollection = {};
$scope.isGlobalVisible = {};

$http.get('rest/obz/getAllObjects').success(function(obdata) {
console.log(obdata);
$scope.rowCollection = obdata;
console.log(rowCollection);
}).error(function() {
console.log("Error");
});
}
});

我想在 AngularJS.as 中将上面的数组拆分为 obj1、obj2、obj3、obj4、obj5 和 obj6 的单独数组

obj1 = [{1039751,895321,926384,837537,867152,1003783,864287}]

obj2 = [{"ABC","PQR","MNO","LMN","JKL","XYZ","DEF"}]

等等。

如何在js中将它们分开?

最佳答案

您是否尝试过 angular.forEach 并将值推送到新对象上?

类似于

$http.get('rest/obz/getAllObjects')
.success(function(obdata){
console.log(obdata);
$scope.rowCollection = obdata;
console.log(rowCollection);

angular.forEach($scope.rowCollection, function(value, key) {
if (this[key] == undefined) {
this[key] = [];
};
this[key].push(value);
});
}).error(function(){
console.log("Error");
});

关于javascript - AngularJS 数组分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40201820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com