赞
踩
重点在与a -= 1
,要让a
随着被截取后数组长度的变化而变化,截取一个,a
少一次。
let val = this.childData.chackNumber
for (let a = 0; a < val.length; a++) {
if (val[a].chack == false) {
val.splice(a,1)
a -= 1 //每删除一个项就让a减少一个 保持a和长度同步
}
}
数据结构如下:
chackNumber: [ { floorID:true, chack: true, name: "[01]" }, { floorID:false, chack: false, name: "[02]" }, { floorID:false, chack: false, name: "[03]" }, { floorID:false, chack: false, name: "[04]" }, { floorID:true, chack: true, name: "[05]" }, { floorID:false, chack: false, name: "[06]" }, { floorID:true, chack: true, name: "[07]" }, { floorID:false, chack: false, name: "[08]" }, { floorID:true, chack: true, name: "[09]" }, { floorID:true, chack: true, name: "[10]" }, { floorID:false, chack: false, name: "[11]" } ]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。