this.dataPTR = this.dataPTR.map(item1 => { // 预先筛选和查找,避免在每个 map 调用中重复 const filteredList = resp.data.enrollChoosingDetailsAgencyList .filter(obj => obj.seniorBatch !== 0 && obj.seniorBatch !== 99); // 使用 forEach 并提前退出 item1.enrollChoosingSeniorRuleVoList.forEach((item, index) => { filteredList.forEach((item2,index)=>{ if(item1.seniorBatch === item2.seniorBatch && item1.seniorSub ===item2.seniorSub){ item.enrollCode = item2.enrollCode; item.enrollName = item2.enrollName; } }) }); // 返回新对象或原对象 return item1 });优化代码
理解问题this.dataPTR = this.dataPTR.map(item1 => { // 预先筛选和查找,避免在每个 map 调用中重复 const filteredList = resp.data.enrollChoosingDetailsAgencyList .filter(obj => obj.seniorBatch !== 0 && obj.seniorBatch !== 99); // 使用 forEach 并提前退出 item1.enrollChoosingSeniorRuleVoList.forEach((item, index) => { filteredList.forEach((item2,index)=>{ if(item1.seniorBatch === item2.seniorBatch && item1.seniorSub ===item2.seniorSub){ item.enrollCode = item2.enrollCode; item.enrollName = item2.enrollName; } }) }); // 返回新对象或原对象 return item1 });优化代码
已完成理解「this.dataPTR = this.dataPTR.map(item1 => { // 预先筛选和查找,避免在每个 map 调用中重复 const filteredList = resp.data.enrollChoosingDetailsAgencyList .filter(obj => obj.seniorBatch !== 0 && obj.seniorBatch !== 99); // 使用 forEach 并提前退出 item1.enrollChoosingSeniorRuleVoList.forEach((item, index) => { filteredList.forEach((item2,index)=>{ if(item1.seniorBatch === item2.seniorBatch && item1.seniorSub ===item2.seniorSub){ item.enrollCode = item2.enrollCode; item.enrollName = item2.enrollName; } }) }); // 返回新对象或原对象 return item1 });优化代码」
展开阅读网页