我目前正在尝试为自己的工作制作工具,时间安排让我很烦。希望有人可以在这里提供帮助。以下是我目前拥有的代码。问题是当我抓取选定的项目并运行$("#JJ_HOLDER").load()
时,有时它不等待完成。我需要在回调函数中完成所有操作,然后仅在完成后运行submitTaskbyHolder()
。任何帮助都将不胜感激!
最终目标:运行RunCad()
并将其加载到$("#JJ_HOLDER")
中,然后运行submitTaskbyHolder()
然后清空并重复另一个数据集(parseInt(selected[i])
)
function submitTaskbyHolder(){
var loginUser = $("#hdnUserID").data('value');
$.ajax({
type: "POST",
url: app.global.AppPath + 'WorkRequestDetails/SubmitWorkRequestDetails/',
data: $('#FormID').serialize(),
dataType: 'json',
success: function (result) {
if (result.Status == "Show Add Module") {
app.workRequestDetails.OpenWorkRequestDetailsPopup("Submit");
}
else {
if (result.Status == "Module submitted.") {
if (result.ModuleAndStatus.CurrentAssignedId == loginUser) {
app.modalPopup.isCancel = false;
$("#BTNStop").click();
app.workRequestDetails.display_notifyresultA("Successfully submitted work request.");
$('#HFCurrentModuleID').val(result.ModuleAndStatus.ModuleId);
$('#HFCurrentStatusID').val(result.ModuleAndStatus.StatusId);
$('#txtModule').val(result.ModuleAndStatus.ModuleName);
$('#txtStatus').val(result.ModuleAndStatus.StatusName);
console.log('submitted');
}
else {
app.modalPopup.isCancel = false;
app.layoutdash.display_notifyresult("Successfully submitted work request.");
console.log('submitted');
}
}
else {
swal(result.Status);
}
}
},
error: function (result) {
swal(result.Status);
}
});
}
var i = 0;
function RunCad() {
selected = app.dashboardGridview.selectedItems;
if(selected.length == 0){
swal({title: "Error",
text: "Ensure there is more than one selected!",
icon: "error",
button: "Okay",
});
}else{
setTimeout(function () {
$("#JJ_HOLDER").empty();
$("#JJ_HOLDER").load(app.global.AppPath + 'WorkRequestDetails/GetWorkRequestDetails/', { projectID: parseInt(selected[i]) },function() {
$(body).css('padding-right', '0px');
app.addWorkRequest.LoadTooltipsterToPopup();
app.multiSelectSettings.MultiSelectSettings();
app.modalPopup.Loadfunctions('WorkRequestDetails/GetWorkRequestDetails/');
app.modalPopup.FixTabPressModalPopup();
submitTaskbyHolder();
console.log(selected[i] + ' is complete!');
});
i++;
if (i+1 < app.dashboardGridview.selectedItems.length) {
RunCad();
}else{
app.modalPopup.ReloadDashboardView();
}
}, 3000)
}
}