如果在名為 this.constraint.costs 的 jsonArray 中找到零值,我需要停止我的函式 myFunction() 進行處理。
這是我的第一個功能:
myFunction(){
if(this.zeroValueCosts()){
console.log(" Found an integer 0 value, I need to stop my function")
return;
};
}
這是我第二個假設的異步函式:
async zeroValueCosts(){
await this.constraint.costs.forEach(function(cost){
if(cost.value = 0){
return true;
}
else{
return false;
}
});
}
它不起作用,沒有顯示錯誤
在 forEach 回圈結果中使用 async/await 的正確方法是什么?
這是 this.constraints.costs 陣列:
costs: [{
"name": "new cost",
"value": 0.06666
},{
"name": "new cost 2",
"value": 0.05666
}]
uj5u.com熱心網友回復:
好吧,你甚至不需要 async await
async myFunction(){
if(this.zeroValueCosts()){
return;
};
}
zeroValueCosts(){
return constraint.costs.some(({ value }) => value === 0);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/338435.html
標籤:Vue.js
