一個JSON陣列內的兩個項目這是我的代碼:如何分割的角度
$scope.center_name = [];
$scope.stats = ["Stats"];
$scope.totMemCenterData = [];
var query = "SELECT count(*) as tot_mem, centers.name as center_name FROM mem_groups "
+ "INNER JOIN centers ON mem_groups.center_id=centers.id GROUP BY centers.id";
$cordovaSQLite.execute(db, query, [])
.then(function(res){
if (res.rows.length > 0) {
for (var i=0; i < res.rows.length; i++) {
$scope.totMemCenterData = res.rows.item(i);
console.log(JSON.stringify($scope.totMemCenterData));
}
}
}, function(err){
// $cordovaToast.showShortBottom('Something Went Wrong').then(function(success){}, function(err){});
console.log(err.message);
});
這是console.log(JSON.stringify($scope.totMemCenterData));
結果:
{"center_name":"AFG - ANONANG","tot_mem":6}
{"center_name":"BAM - BUENAVISTA","tot_mem":3}
{"center_name":"GHT - TAGAS","tot_mem":2}
我希望把所有center_names在一個陣列中還另一個陣列上的tot_mem。我想這是這樣的:
中心: 「AFG - ANONANG」, 「BAM - BUENAVISTA」, 「GHT - TAGAS」 Tot_mem:6,3,2 我要把這些值的圖表上。在x軸和tot_mem在y軸
檢查答案 – Sajeetharan
我會嘗試。謝謝! @Sajeetharan –
標記爲答案,如果它有幫助 – Sajeetharan