我需要收集对象数组中的每个属性值以分离属性数组,有什么简单的方法可以做到这一点。下划线和angularjs实用程序都可以。
例如,我有一个对象数组,
$scope.expNumArray = [];
$scope.itemHrArray = [];
$scope.highReArray = [];
$scope.rowdata = [{
"expNum": "678",
"itemHr": "",
"highRe": "C"
}, {
"expNum": "978",
"itemHr": "3",
"highRe": ""
}];
现在我需要有以下内容:
$scope.expNumArray = ["678", "978"];
$scope.itemHrArray = ["", "3"];
$scope.highReArray = ["C",""];
答案 0 :(得分:2)
你可以使用angular forEach
来实现这一目标。
$scope.expNumArray = [];
$scope.itemHrArray = [];
$scope.highReArray = [];
$scope.rowdata = [{
"expNum": "678",
"itemHr": "",
"highRe": "C"
}, {
"expNum": "978",
"itemHr": "3",
"highRe": ""
}];
angular.forEach($scope.rowdata,function(value,key){
$scope.expNumArray.push(value["expNum"]);
$scope.itemHrArray.push(value["itemHr"]);
$scope.highReArray.push(value["highRe"]);
});
答案 1 :(得分:0)