我有一个使用$ resource与REST API通信的工厂。当我删除一个对象然后我尝试在回调中查询以保持列表中相同数量的元素时出现问题。这就像我无法访问回调函数中看起来像这样的任何变量:
this.delete = function() {
var item = new Luminaria(this.selectedtem);
item.$delete(function(){
this.selectedtem = this.emptyItem();
this.backupItem = undefined;
this.items = Luminaria.query();
});
$("#itemModal").modal('hide');
}
'this'在回调函数中是未定义的......任何想法?
答案 0 :(得分:0)
如果您使用$resource
与REST API通信,结果将为asynchronous
。因此,您无法访问回调函数中的变量。