合并时段相同的数据和时段中类型相同的数据:
let content1 = []
if (this.recordMap.get(key) != undefined) {
this.recordMap.forEach((val) => {
if (val.length > 1) {
let index = []
let content = []
val.forEach(item => {
if (index.indexOf(item.sd) === -1) {
index.push(item.sd)
let data = {
sj: item.sj,
sd: item.sd,
gznr: item.gznr,
nr: [item]
}
content.push(data)
} else {
content.forEach(value => {
if (value.sd == item.sd) {
value.gznr += "," + item.gznr
value.nr.push(item)
}
})
}
})
content.forEach(va => {
let index = []
let newData = []
let val = JSON.parse(JSON.stringify(va))
val.nr.forEach(item => {
if (index.indexOf(item.lx) === -1) {
index.push(item.lx)
newData.push(item)
} else {
newData.forEach(value => {
if (value.lx == item.lx) {
let str = value.gznr + ", " + item.gznr
value.gznr = str
} else {
}
})
}
})
va.nr = newData
})
content.forEach(item => {
if (item.sj == key) {
content1.push(item)
}
})
}
})
}
注:数据拷贝let val = JSON.parse(JSON.stringify(va))一定要!!!!
如果不拷贝数据,字符串内容中的第二个内容会被循环多次连接起来。(目前原因没搞懂)