我调用了belongsTo关联生成的getter函数:
token.getUser({
callback: function(user, operation) {
console.info('getUser callback');
Ext.Viewport.unmask();
console.dir(operation);
},
failure: function(user, operation) {
console.info('getUser failure');
},
success: function(user) {
console.info('getUser success');
}
});
我的控制台显示以下内容:
getUser success Auth.js:74
getUser failure Auth.js:69
getUser callback Auth.js:64
undefined
有人可以告诉我这是如何运作的吗? docs没有多大帮助。
答案 0 :(得分:2)
肯定是一个错误。查看createGetter
方法的代码:
if (options.reload === true || instance === undefined) {
...
} else {
args = [instance];
scope = scope || model;
Ext.callback(options, scope, args);
Ext.callback(options.success, scope, args);
Ext.callback(options.failure, scope, args);
Ext.callback(options.callback, scope, args);
return instance;
}
如果已加载相关模型,则会不加选择地调用所有回调。
您可以使用以下解决方法,因为我们发现没有为缓存实例调用第二个参数:
token.getUser({
callback: function(user, operation) {
// independent of success
if (operation) {
if (operation.wasSuccessful()) {
// successful load
} else {
// failed load
}
} else {
// retrieved from the cache (indicates previous success)
}
}
});