我有一個功能,推動來自其他功能,也解決承諾數組承諾。我只是想知道這個代碼是否可以。JQuery延遲解決其他延遲
這裏的主要功能是
/// <summary>Process the validation results (invalid IDR records will have the iop=4)</summary>
this.processValidationResults = function()
{
var promises = [];
var count = (self.idrValidationList.length - 1);
$.each(self.idrValidationList, function (index, idrValidationItem)
{
_onProgress(self.utils.formatCounterMessage(index, count, 'Processing Validation Items'));
if (idrValidationItem.is_valid = 0)
{
//there is a problem with this IDR record
//update the idr_insp table
promises.push(self.updateInvalidEntity(self.configEntities.idr_insp, idrValidationItem.idr_insp_id));
promises.push(self.updateInvalidChildren(self.configEntities.idr_insp, idrValidationItem.idr_insp_id));
}
else
{
//push resolved promise
promise.push($.when());
}
});
return ($.when.apply($, promises));
}
這裏是由上述功能
/// <summary>Update the invalid record, sets the IOP field to 4 [Cannot sync due to issue]</summary>
/// <param name="entity" type="Object">GLobal entity definiton </param>
/// <param name="tabletId" type="Int">Primary Key on the tablet to change</param>
this.updateInvalidEnity = function (entity, tabletId)
{
//update the record with the new ID and IOP status
var updateSql = 'UPDATE ' + entity.name + ' SET iop=? WHERE ' + entity.key_field + '=?';
//update the record
return (self.db.executeSql(updateSql, [4, tabletId]));
}
/// <summary>Update the invalid child records, sets the IOP field to 4 [Cannot sync due to issue]</summary>
/// <param name="entity" type="Object">GLobal entity definiton </param>
/// <param name="keyId" type="Int">Foreign Key on the tablet to change</param>
this.updateInvalidChildren= function (parentEntity, keyId)
{
var promises = [];
$.each(parentEntity.child_entities, function (index, child)
{
var def = new $.Deferred();
var updateSql = 'UPDATE ' + child.child_name + ' SET iop=? WHERE ' + child.key_field + '=?';
promises.push(self.db.executeSql(updateSql, [4, keyId]));
});
return ($.when.apply($, promises));
}
而且所有上述方法是推動下面的遞延調用的函數。
/* Executes the sql statement with the parameters provided and returns a deffered jquery object */
this.executeSql = function (sql, params)
{
params = params || [];
var def = new $.Deferred();
self.db.transaction(function (tx)
{
tx.executeSql(sql, params, function (itx, results)// On Success
{
// Resolve with the results and the transaction.
def.resolve(itx, results);
},
function (etx, err)// On Error
{
// Reject with the error and the transaction.
def.reject(etx, err);
});
});
return (def.promise());
}
這是鏈條的聲音?還沒有測試,但我認爲這是確定的。只是想一些其他的眼睛在這之前,我繼續......
這是不是有點太多問,只是檢查是否有人可能會發現一個問題,如果你甚至沒有自己測試它?! 爲什麼你不能自己發現這是否正常工作? – Martin
@Martin,因爲當前正在開發的本地平板電腦數據庫中沒有加載數據。我的任務是編寫沒有數據的數據同步代碼。只是問一個問題。我不認爲這個問題對於任何理解延期的人來說都很難。所以提供一個答案或保持你的無意義的評論給自己... – gdex
很積極... – Martin