0
承諾完成後,我無法執行if
語句。即使在使用$.when.apply(null, [promise goes here]).then()
後;也不按順序工作。我哪裏錯了?jQuery承諾執行順序,然後是其他語句塊
self.model.findGuests(expense.ExpNumber)
.then(function (expReportGuests) {
return expReportGuests && expReportGuests.length > 0;
});
var hasItemizeOrGuests = this.options.selectedExpenses.some(expense => (expense.ItemizedLines && expense.ItemizedLines.length)
|| ($.Deferred().resolve(self.model.findGuests(expense.ExpNumber)
.then(function (expReportGuests) {
return expReportGuests && expReportGuests.length > 0;
}).promise())));
if (hasItemizeOrGuests) {
// do something
}
我想使用hasItemizeOrGuests進行驗證,但必須執行諾言以將布爾值分配給hasItemizeOrGuests變量。但'if'語句稍後執行的承諾是將值設置爲hasItemizeOrGuests。如何使它順序執行 – srikanth