E企盈营销工具技术服务商 热线:4006-838-530

解决小程序多层循环导致页农安县E企盈小程序面加载缓慢问题

小程序多层循环嵌套导致加载慢使用循环的时候有的需要多次循环列表找到最终需要的数据,但是会导致接口以及页面加载缓慢,此时建议将循环单独取出,并发触发循环,而不是循环完一个再循环下一个正确实例let obj = this.data.myDefaultCar;      let setId = '';      let arry1 = [];      let arry2 = [];      if (this.data.myDefaultC开通牛仔裤小程序电话:4006-838-530ar) {        this.setData({          curClass: {            gcName: obj.zichexi,            scName: obj.brandName,            gcId: ''          },        })        let newList = this.data.carArr;        newList.forEach(item = { // 循环使列表滑动指定位置          let newObj = item.brands          for (var k in newObj) {              if (newObj[k].brandName === this.data.myDefaultCar.brandName) {                this.setData({                  toView: 'a_' + k,                  setId: newObj[k].brandId,                  arry1: item.brands                })                // console.log(k + '在数组中出现的位置为' + this.data.toView);              }          }        });        this.data.arry1.forEach(res = { // 循环使列表对应车型厂商展开          if (res.brandId == this.data.setId) {            res.childShow = !res.childShow;          } else {            res.childShow = true;          }          this.setData({            carArr: newList,            arry2: res.factoryList          });          return true;        })        this.data.arry2.forEach(respone = { // 循环出厂商id进行搜索类表          if (respone.factoryName == this.data.myDefaultCar.zichexi) {            this.setData({              factoryid: respone.factoryid            })          }        });        this.getStoreGoods()      }

错误实例let obj = this.data.myDefaultCar      let setId = ''      if (this.data.myDefaultCar) {        this.setData({          curClass: {            gcName: obj.zichexi,            scName: obj.brandName,            gcId: ''          },        })        let newList = this.data.carArr;        newList.forEach(item = {          let newObj = item.brands          for (var k in newObj) {              if (newObj[k].brandName === this.data.myDefaultCar.brandName) 开通医用口罩小程序电话:4006-838-530{                console.log('*****',newObj[k].brandId)                this.setData({                  toView: 'a_' + k,                  setId: newObj[k].brandId                })                console.log(k + '在数组中出现的位置为' + this.data.toView);              }    开通医用床上护理小程序电话:4006-838-530      }          newObj.forEach(res = {            if (res.brandId == this.data.setId) {              res.childShow = !res.childShow;            } else {              res.childShow = true;            }            this.setData({              carArr:newList            });            return true;            if (res.brandName == this.data.myDefaultCar.brandName) {              this.setData({                CarParentId: res.brandId              })              res.factoryList.forEach(respone = {                if (respone.factoryName == this.data.myDefaultCar.zichexi) {                  this.setData({                    factoryid: respone.factoryid                  })                }              });            }          })        });        this.getStoreGoods()      }

这两种加载速度有天壤之别,以后要注意了

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 解决小程序多层循环导致页农安县E企盈小程序面加载缓慢问题
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

模王系统开发

联系我们升级日志

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏