开发中遇到了一个问题,数据是接口返回回来才进行赋值,可是数据的逻辑处理在赋值前,这样问题就很大了。
js处理异步,因为涉及的方法和接口比较多,于是打算用anync和await来解决问题
JSON.stringify(that.oldSourceIdList.sort())?===?JSON.stringify(checkedSourceList.sort())
比较对象数组是否相等
JSON.stringify(that.oldSourceIdList.sort())?===?JSON.stringify(checkedSourceList.sort())
params = { [that.curUserOrGroupId]: "" };
// 先查出当前用户已经绑定的坐席权限,备用
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();
|