var data=[
{invoiceID: "AAA", invoiceCode: "AAA12234", invoiceNumber: "1232353", invoiceType: 1, totalPriceTax: 23},
{invoiceID: "BBB", invoiceCode: "BBB222", invoiceNumber: "22222", invoiceType: 1, totalPriceTax: 27}
];
数组中某列值拼接成字符串
// 逗号拼接
this.currentRow.invoiceCode = data
.map(function(obj: any) {
return obj.invoiceCode;
})
.join(',');
// 逗号拼接 简化写法
this.currentRow.invoiceCode = data
.map((obj: any) => {
return obj.invoiceCode;
})
.join(',');
数组中某列值累加
// 值累加
this.currentRow.invoiceAmount = data.reduce(function(total: any, currentValue: any) {
return total + currentValue.totalPriceTax;
}, 0);
this.$forceUpdate();
数组遍历
this.data.forEach((u: any) => {
u.invoiceList.forEach((c: any) => {
this.selectedInvoiceList.push(c);
});
});
// 转化成其他
rowdata.forEach((u: any) => {
invoicelist.push({
invoiceCode: u.invoiceCode,
invoiceNumber: u.invoiceNumber,
invoiceID: u.invoiceID,
});
});
数组过滤(剔除)元素
that.needRemoveInvoivceCodes = that.selectedInvoiceList.filter(value => {
return row.invoiceCodes.indexOf(value.invoiceCode) === -1;
})
数组过滤元素后返回指定列
that.needRemoveInvoivceCodes = that.selectedInvoiceList
.filter(value => {
return row.invoiceCodes.indexOf(value.invoiceCode) === -1;
})
.map((obj: any) => {
return obj.invoiceCode;
});
版权属于:dingzhenhua
本文链接:https://www.dcmickey.cn/skill/131.html
转载时须注明出处及本声明
最后一次更新于2020-07-28
0 条评论