これは初回ですので、基本的にforEachが完了しました。それ以降の処理のために別の関数を呼び出す場合は、1回だけforEachを使用して印刷します。insertIDBEvents
次回の呼び出しでは印刷されません。 forEachに約束を使用する正しい方法は何ですか?promise inisde forEachの使い方forEachのチェックは完了しましたか?
nodeCtrl.js
var ctr = 0;
var insertIDBEvents = [];
data.forEach(function(element, index, array) {
event = JSON.parse(element.variables.event.value);
if (typeof element.variables.caseIdFound !== 'undefined') {
//asynchronous(function(data){
Promise.all(array)
.then(function(element) {
ctr++;
console.log("caseIdFound boolean", element.variables.caseIdFound.value);
insertIDBEvents.push(element);
console.log(insertIDBEvents);
if (ctr === array.length) {
console.log('IDBinsert', JSON.stringify(insertIDBEvents));
anotherFunction(insertIDBEvents)
}
})
}
});
anotherIDBEvents (data) {
// do something with data
}
私が条件とその配列がまだのforEach – hussain
@hussainによって処理されているが、そのように動作していない場合、あなたは同期と非同期コードをそのように混在させることはできませんだけで内部の約束を適用したかったです。 –