背景:
设备面板有12个插槽:但是服务器返回来的数据是不完整的(有插板才会有数据)
每张卡有6个灯:同理,服务器返回来的数据也是不完整的(有插卡才有灯)
界面上的需要是:必须要12个插槽,每张卡得有6个灯。所以就要把缺失的给补全。代码如下:
this.detailInfoList.map((e, k) => {
while (e.blade > this.devicesMsg.length && this.devicesMsg.length < 12) {
if (e.blade === this.devicesMsg.length + 1) {
e.isblank = 0
const cardlist = e.cardlist
if (cardlist.length === 6) {
this.devicesMsg.push(e)
} else {
const cardlistNew = []
cardlist.map((e2, k2) => {
while (e2.card > cardlistNew.length && cardlistNew.length < 6) {
if (e2.card === cardlistNew.length + 1) {
cardlistNew.push(e2)
break
} else {
cardlistNew.push({
id: 'null',
card: cardlistNew.length + 1
})
}
}
if (k2 === cardlistNew.length - 1 && cardlistNew.length !== 6) {
while (cardlistNew.length !== 6) {
this.devicesMsg.push({
id: 'null',
card: cardlistNew.length + 1
})
}
}
})
}
break
} else {
this.devicesMsg.push({
blade: this.devicesMsg.length + 1,
cardlist: [],
isblank: 1
})
}
}
// 最后一张卡
if (k === this.detailInfoList.length - 1 && this.devicesMsg.length !== 12) {
while (this.devicesMsg.length !== 12) {
this.devicesMsg.push({
blade: this.devicesMsg.length + 1,
cardlist: [],
isblank: 1
})
}
}
})