关于这个问题,我正在尝试添加一个回调来取回数据。所以我尝试了这个:
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);
}
});
}
我以为在上一个问题之后我对闭包有了更好的理解,但我想我没有......我收到以下错误:
Uncaught TypeError: Object [object Window] has no method 'callback'
我在这里做错了什么?
编辑
以下是 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);
}