백엔드 시스템에 대한 동기화 호출을 생성하는 함수가 세 가지 있습니다 (fnOne, fnTwo, fnThree). 나는 올바르게하고 있지 않다는 것을 알고 있지만, 올바른 길을 찾아 낼 수는 없습니다.지연된 약속 - 완료 될 때마다 함수를 하나씩 실행
나는 각이 완료된 후가 그 중 하나를 호출하는 시도하여 오프 시작입니다 :
그러나, fnOne 이미 내부 지연된 개체가 그 문제가 해결 될 때 내 약속을 해결한다.$.when(oController._fnOne()).done(function(){
console.log("fn one complete");
});
기능
_fnOne: function(){
var oController = this;
//when the deferred is done in _checkInstanceStatus, it is resolving the above, rather than the pDeferred in this function resolving the above.
$.when(oController._checkInstanceStatus(oParams)).done(function(oStatusData) {
//does some stuff
return $.Deferred(function() {
var pDeferred = this;
//does a call for data and upon success i will resolve ..
pDeferred.resolve();
});
});
}
다른 기능
_checkInstanceStatus: function(oParams){
return $.Deferred(function() {
var pDeffered = this;
//does a call for data and upon success i will resolve...
pDeffered.resolve(data);
});
});
},
그들과 같이, 하나 하나 실행 있도록 그런 계획이 그들을 시도하고 체인하는 것입니다
$.when(oController._fnOne())
.then(oController._fnTwo())
.then(oController._fnThree())
.done(function(){
console.log("all complete!");
});
당신에게 고체 대답을 줄 수있는 문제가 확실히 충분한 정보가없는 난 두려워. 'fnOne'이하는 "호출"은 무엇입니까? 그것은 Promise 나 Deferred를 반환하는 것입니까? –
@ T.J.Crowder, 회신 해 주셔서 감사합니다. 호출이 데이터를 위해 백엔드 시스템을 호출하는 곳입니다. 호출이 성공적으로 완료된 후 연기 된 문제를 해결하고 있습니다. pDeferred.resolve(); – neeko
백엔드 시스템에 대한 호출은'$ .ajax'를 통해 이루어 집니까? 다시 : 약속이나 거치를 반환합니까, 아니면 ...? –