이것에 대한 전문 지식이 필요합니다.http.get 요청 데이터를 합산하는 방법
나는 http.get 요청을 통해 데이터를 얻고 다음과 같은 JSON 데이터는 다음과 같습니다 합계에서
{"displayTransactionDateTime": "Tue, 19th Sep 2017"
, "transactionDateAndTime": "2017-09-19 18:36:34.0"
, "transactionId": "158131"
, "refTransactionId": null
, "transactionType": "Credit Transfer"
, "creditType": "Transfer"
, "transactionMode": "SYSTEM CREDITS"
, "transactionCurrency": "SYSTEM CREDITS"
, "transactionAmount": "50"
, "credits": "50"
, "creditMessage": ""},
{"displayTransactionDateTime": "Wed, 13th Sep 2017"
, "transactionDateAndTime": "2017-09-13 09:53:28.0"
, "transactionId": "157687"
, "refTransactionId": null
, "transactionType": "Credit Purchase"
, "creditType": "Bought"
, "transactionMode": "CREDIT CARD"
, "transactionCurrency": "AED"
, "transactionAmount": "50"
, "credits": "10"
, "creditMessage": null},
{"displayTransactionDateTime": "Sat, 9th Sep 2017"
, "transactionDateAndTime": "2017-09-09 14:49:42.0"
, "transactionId": "157378"
, "refTransactionId": null
, "transactionType": "Voucher Purchase"
, "creditType": "Spent"
, "transactionMode": "SYSTEM CREDITS"
, "transactionCurrency": "SYSTEM CREDITS"
, "transactionAmount": "5"
, "credits": "5"
, "creditMessage": null}
{
"displayTransactionDateTime": "Tue, 7th Feb 2017"
, "transactionDateAndTime": "2017-02-07 19:11:40.0"
, "transactionId": "34133"
, "refTransactionId": "34132"
, "transactionType": "Credit Award"
, "creditType": "Award"
, "transactionMode": "SYSTEM CREDITS"
, "transactionCurrency": "SYSTEM CREDITS"
, "transactionAmount": "1"
, "credits": "1"
, "creditMessage": "Referral Credit Award"}
{"displayTransactionDateTime": "Sat, 20th Aug 2016"
, "transactionDateAndTime": "2016-08-20 17:50:42.0"
, "transactionId": "10348"
, "refTransactionId": "10347"
, "transactionType": "Credit Received"
, "creditType": "Recieved"
, "transactionMode": "SYSTEM CREDITS"
, "transactionCurrency": "SYSTEM CREDITS"
, "transactionAmount": "1"
, "credits": "1"
, "creditMessage": ""}
나는이 5 creditTypes와 혼합 (100 개) 기록을 가지고있다.
"creditType": "Transfer", "creditType": "Bought", "creditType": "Spent",
"creditType": "Award", "creditType": "Received".
및 각 신용 유형별 크레딧도 있습니다.
버그를 보려면 ng-repeat로 데이터를 표시하고 있지만 완벽하게 작동하고 있습니다.
누구나 어떻게하면 각 신용 유형의 총계를 얻을 수 있습니까? 예를 들어
: creditType : 전송 = creditType : 구입 = creditType : 지출 = creditType : 상 = creditType :? 사전에 =
감사 수상!
function groupBy(arr, key) {
var newArr = [],
types = {},
newItem, i, j, cur;
for (i = 0, j = arr.length; i < j; i++) {
cur = arr[i];
if (!(cur[key] in types)) {
types[cur[key]] = { type: cur[key], data: [] };
newArr.push(types[cur[key]]);
}
types[cur[key]].data.push(cur);
}
return newArr;
};
$scope.groupedItems=groupBy(data,"creditType");
같은
신용 유형별로 "크레딧"합계를 원합니까? –
예 Mr. Surjeet Bhadauriya. 이걸 좀 도와 주실 래요 ?? –