我正在撰寫一個離子應用程式,它通過使用“存盤”來存盤一些表單條目和一些選項。現在我想計算選項,但我總是得到零。
我正在使用以下代碼:
async getAllEntries()
{
let count = 0;
this.trackingEntries = [];
this.storage.forEach((value, key, index) =>
{
if (key != "Options0" && key != "Options1" && key != "Options2" && key != "Options3" )
{
this.trackingEntries.push(value);
count ;
}
})
console.log(this.trackingEntries);
console.log("Count: " count);
}
console.log(this.trackingEntries) 回傳以下物件:
[
{
"timestamp": "1663677073",
"tracking": [
"6",
"4",
"5",
"6"
]
},
{
"timestamp": "1663677073",
"tracking": [
"2",
"2",
"2",
"2"
]
},
{
"timestamp": "1663677073",
"tracking": [
"2",
"2",
"2",
"2"
]
}
]
但計數變數始終為零。我怎么解決這個問題?
uj5u.com熱心網友回復:
我通過使用“then”找到了解決方案。
async getAllPottyTrackingEntries() {
this.trackingEntries = [];
this.storage.forEach((value, key, index) => {
if (key != "Options0" && key != "Options1" && key != "Options2" && key != "Options3") {
this.trackingEntries.push(value);
}
}).then(() => {
console.log("Count: " this.trackingEntries.length)
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/511589.html
上一篇:路由時反應狀態重置(離子)
下一篇:div內的可點擊圖示
