current position:Home>Vue asynchronous processing interface returns data & whether the array of comparison objects is equal

Vue asynchronous processing interface returns data & whether the array of comparison objects is equal

2022-01-27 04:35:27 Rolling mill

There is a problem in the development , The data is assigned only after the interface returns , But the logical processing of data is before assignment , This is a big problem .

js Deal with asynchronous , Because there are many methods and interfaces involved , So I decided to use anync and await To solve the problem

JSON.stringify(that.oldSourceIdList.sort()) === JSON.stringify(checkedSourceList.sort())

Compare object arrays for equality

JSON.stringify(that.oldSourceIdList.sort()) === JSON.stringify(checkedSourceList.sort())

params = { [that.curUserOrGroupId]: "" };
        //  First find out the agent permissions that the current user has bound , spare 

        function getoldSeatIdList() {
           return userRoleMng.getoldSeatIdList(that.curUserOrGroupId).then((data)=>{
            that.oldSeatIdList=data.list.map(item=>item.seat_id);
        })}
        function getoldSourceIdList() {
          return userRoleMng.getoldSourceIdList(that.curUserOrGroupId).then((data)=>{
            that.oldSourceIdList=data.list.map(item=>item.source_id);
        })}

        async function work() {
          await getoldSeatIdList()
          await getoldSourceIdList()
          if(JSON.stringify(that.oldSourceIdList.sort()) === JSON.stringify(checkedSourceList.sort()) && JSON.stringify(that.oldSeatIdList.sort())===JSON.stringify(checkedSeatList.sort())){
            return
          }else if(JSON.stringify(that.oldSourceIdList.sort()) === JSON.stringify(checkedSourceList.sort())) {
                userRoleMng.deleteUserRelat(params).then(()=> {
                  that.bindUserRelat();
                });
        }else if(JSON.stringify(that.oldSeatIdList.sort())===JSON.stringify(checkedSeatList.sort())){
            userRoleMng.deleteSourceUserRelat(params).then(() => {
            that.bindSourceUserRelat()
          });
          }else {
            userRoleMng.deleteSourceUserRelat(params).then(() => {
            that.bindSourceUserRelat().then(()=>{
              userRoleMng.deleteUserRelat(params).then(()=> {
                that.bindUserRelat();
              });
            });
          });
          }
        }
        work();

copyright notice
author[Rolling mill],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270435229109.html

Random recommended