我有一个函数,我在其中调用两个函数,我想完全运行第一个函数然后第二个执行但我无法控制它。
DayCalendar: function(ProviderId, ResourceId, FacilityId, CriteriaDate, statusid) {
MDVisionService.lookups("GetAppointmentStatus").done(function(result) {
appstatus = result;
});
Scheduling_Calendar.SearchDaySlotSchedule(ProviderId, ResourceId, FacilityId, CriteriaDate, statusid).done(function (response) {
if (response.status != false) {
}
});
}
答案 0 :(得分:1)
将第二个函数Scheduling_Calendar.SearchDaySlotSchedule
移动到第一个函数MDVisionService.lookups
的回调
DayCalendar: function(ProviderId, ResourceId, FacilityId, CriteriaDate, statusid) {
MDVisionService.lookups("GetAppointmentStatus").done(function(result) {
appstatus = result;
Scheduling_Calendar.SearchDaySlotSchedule(ProviderId, ResourceId, FacilityId, CriteriaDate, statusid).done(function (response) {
if (response.status != false) {
}
});
});
}
答案 1 :(得分:0)
我会写一些类似的东西:
DayCalendar: function(ProviderId, ResourceId, FacilityId, CriteriaDate, statusid, callback) {
MDVisionService.lookups("GetAppointmentStatus").done(function(result) {
appstatus = result;
//callback(arguments) //if you need to call it here
});
callback(arguments);
}
schedule: function(ProviderId, ResourceId, FacilityId, CriteriaDate, statusid){
var args = arguments;
return function() {
return Scheduling_Calendar.SearchDaySlotSchedulea.apply(this, args).done(function (response) {
if (response.status != false) {
}
});
}
//call
DayCalendar(ProviderId, ResourceId, FacilityId, CriteriaDate, statusid, schedule());