this question과 관련하여 콜백을 추가하여 데이터를 다시 가져 오려고합니다. 그래서 나는이 시도 :자바의 재귀 비동기 콜백
Uncaught TypeError: Object [object Window] has no method 'callback'
: 나는 이전 질문 후 폐쇄의 더 나은 이해를하지만 난 ... 나는 다음과 같은 오류가있어하지 않는 것 같아요 생각
var subgroupIds = [];
var that = this;
this.getSubGroups = function (groupId,callback) {
var anotherObject = this;
this.getGroups("groupId="+groupId, function(groups) {
if ($.isEmptyObject(groups)) {
return;
} else {
$.each(groups, function(index,group) {
subgroupIds.push(group.id);
that.getSubGroups(group.id);
});
anotherObject.callback(group.id);
}
});
}
여기서 내가 뭘 잘못하고 있니?
편집
여기에 기능 getgroups의 내용이다 :
this.getGroups = function(filter,callback,error_callback) {
this.getJSON('/'+apiVersion+'/groups/',function(data){
// run through the filter engine
output = runFilter(data, filter);
callback(output);
},error_callback);
}
'this.getGroups'는 (는)'anotherObject.getGroups'이어야합니까? –
왜'that' 대신'anotherObject'를 사용합니까? 그리고 왜 당신은 속성에 콜백합니까, 당신은 함수 인자를 콜백하고 싶지 않습니까? – Bergi
'this' /'that'은 무엇입니까? 'this.getSubGroups'를 선언 할 때,'this'는'window'를 가리 킵니다. 그래서'this'가 올바른 것을 참조하도록하기 위해 뭔가를하지는 않을 것입니다. 그러면 'anotherObject'는 똑같은'window'를 참조합니다. 또한, 왜 당신은'anotherObject.callback (group.id)'를 사용하려고합니까? 'callback (group.id);를 원합니까? – Ian