异步问题处理

一、内层列表数据包含在最外层列表的某个属性中,添加没刷新问题(异步问题)
1.对的方法
在这里插入图片描述

2.错的方法
在这里插入图片描述
在这里插入图片描述

二、new promise 异步调用(JSON数据组装)

function getTypeList(type) {
  return new Promise(function (resolve, reject) {
    getElecIdentPageApi({ current: 1, size: 200, deviceType: type }).then(
      res => {
        let arr = [];
        if (res.code === 0) {
          res.data.records.forEach(el => {
            let obj = {
              a: el.a,
              b: el.b,
              c: el.c
            };
            arr.push(obj);
          });
          resolve(arr);
        } else {
          reject(res.msg);
        }
      }
    );
  });
}
function handleData() {
  let elecList = [];
  for (let i = 0; i < formData.elecType.length; i++) {
    getTypeList(formData.elecType[i]).then(item => {
      var obj = {
        deviceType: formData.elecType[i],
        data: item
      };
      elecList.push(obj);
      formData.elecListJsonStr =
        `{ "identifier": "elecIdent", "elecList":` +
        JSON.stringify(elecList) +
        `}`;
    });
  }
}
  1. 数据上万条了要异步加载
// function getDeviceList(current) {
//   return new Promise(function (resolve, reject) {
//     getLotDevicePage2Api({ current: current, size: 1000, nodeType: 3 }).then(
//       res => {
//         if (res.code === 0) {
//           resolve(res.data.records);
//         } else {
//           reject(res.msg);
//         }
//       }
//     );
//   });
// }
// function getInitData() {
//   let clientData = [];
//   getLotDevicePage2Api({ current: 1, size: 1, nodeType: 3 }).then(res => {
//     let current = Math.ceil(res.data.total / 1000);
//     for (let i = 1; i <= current; i++) {
//       getDeviceList(i).then(item => {
//         clientData.push(item);
//         if (i === current) {
//           let flat = clientData.reduce((prev, next) => {
//             return prev.concat(next);
//           });
//           let mapAllData = flat.filter(el => {
//             return !validatenull(el.lon) && !validatenull(el.lat);
//           });
//           data.mapData = [...mapAllData];
//         }
//       });
//     }
//   });
//   getfeedBack(); //用户反馈
//   getCustHandle(); //客服处理

// }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值