一旦所有前面的函數完成,我試圖執行我的函數HideEmptyTile。使用Promise.all在其他的函數之後執行一個函數
我到目前爲止使用TimeOut,但這不是一個真正的做我想做的事情的正確方法。
這裏是我以前的代碼:
retrieveAccountOpenWithVisitObjectif(userId, processOpenWithVisitObjectif);
retrieveAccountOpen(userId, processAccountOpen);
retrieveAllActivitiesOpen(userId, processAllActivitiesOpen);
setTimeout("HideEmptyTile()", 800);
我發現我可以用一個其它的回調函數的研究較少之後,但似乎Promise.all作爲已經建立了我的情況。所以,我做了下面的代碼:
Promise.all(
retrieveAccountOpenWithVisitObjectif(userId, processOpenWithVisitObjectif),
retrieveAccountOpen(userId, processAccountOpen),
retrieveAllActivitiesOpen(userId, processAllActivitiesOpen)).then(HideEmptyTile());
的問題是,這不是我想有,因爲函數HideEmptyTile沒有其他功能之後執行的行爲。
我是否用錯誤的方式使用Promise.all?
你將它傳遞給'then'當調用'HideEmptyTile'。拿出'()' – lascort