1.状态码版本
依据四个筛选条件,分为1111 1110 ... 0000,共17种状态(本代码不完整,未写全,自己意会的)
function toNum(v) { if (v) { return 1; } else { return 0; } } this.sCode = toNum(tDate) + "" + toNum(tName) + "" + toNum(tDep) + "" + toNum(tState); console.log("sCode", this.sCode); this.tempData = []; const newDate = this.tableData.filter((key) => { switch (this.sCode) { case "1111": if ( key.date == tDate && key.name == tName && key.department == tDep && key.statement == tState ) { console.log("1111"); this.tempData.push(key); } break; case "1110": if ( key.date == tDate && key.name == tName && key.department == tDep ) { console.log("1110"); this.tempData.push(key); } break; default: break; } });
这种版本写起来很麻烦,不过顶用哈哈哈
2.watch版本,之前一直有个误区,没有及时保存上次筛选后的结果,导致只能1次筛选,现在可以重复筛选了。
不过还是有BUG,如果进行了错误的筛选,需要清除筛选后再重新筛选
inputName() { let temp = []; let tName = this.inputName; if (tName) { const newData = this.tempData.map((key) => { if (key.name == tName) { console.log("filter one"); temp.push(key); } }); this.tempData = temp; } },