我的清单如下:
[{"center":"LFEEAPP","cause":"S ","total":66},{"center":"LFFFAD","cause":"S","total":78},{"center":"LFMMAPP","cause":"C","total":143},{"center":"LFMMAPP","cause":"T","total":0}]
现在,我想用reduce方法添加中心的所有值,包括:'APP'和'AD',并将标签更改为'APP',所以对于这个列表示例,我创建的管道必须返回: APP:209(总计)和 LFFFAD:78
管道:
export class MergeCentresAppPipe implements PipeTransform {
transform(listCount: ListCount[]): ListCount[] {
const totalCenterApp = listCount
.filter(count => count.center.includes('APP'))
.map(count => count.total)
.reduce((sum, current) => sum + current, 0);
const centerApp: ListCount = {
center: 'APP',
cause: '',
total: totalTimeCenterApp,
};
const centerMerged = listCount.filter(count => !count.center.includes('APP'));
centreMerged.push(centerApp);
return centerMerged;
}
}
如何将“AD”字符串添加到过滤器以获取: APP:287(APP:209 + LFFFAD:78)谢谢您的帮助