Sencha Touch 2:belongsTo关联回调用法? [英] Sencha Touch 2: belongsTo association callback usage?

查看:134
本文介绍了Sencha Touch 2:belongsTo关联回调用法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我调用一个belongsTo协议生成的getter函数:

  token.getUser({
callback:function ,操作){
console.info('getUser callback');
Ext.Viewport.unmask();
console.dir(operation);
},
失败:function(user,operation){
console.info('getUser failure');
},
success:function(user){
console.info getUser success');
}
});

我的控制台显示以下内容:

  getUser成功Auth.js:74 
getUser失败Auth.js:69
getUser回调Auth.js:64
undefined

有人可以告诉我这是如何工作的? 文档没有帮助很多。

解决方案

绝对是一个错误。看看 createGetter 方法:

  if(options.reload === true || instance === undefined){
...
} else {
args = [instance];
scope = scope ||模型;

Ext.callback(options,scope,args);
Ext.callback(options.success,scope,args);
Ext.callback(options.failure,scope,args);
Ext.callback(options.callback,scope,args);

返回实例;
}

如果相关联的模型已经加载,所有回调都将被无差异地调用。 / p>

您可以使用以下解决方法,因为我们看到第二个参数不是为缓存实例调用的:

  token.getUser({
callback:function(user,operation){

//独立于成功

if(操作){
if(operation.wasSuccessful()){
//成功加载
} else {
//加载失败
}
} else {
//从缓存中检索(表示以前的成功)
}
}
});


I call a belongsTo assocation generated getter function:

        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');
            }
        });

My console shows the following:

getUser success Auth.js:74
getUser failure Auth.js:69
getUser callback Auth.js:64
undefined

Can someone please enlighten me how this works? The docs doesn't help much.

解决方案

Most certainly a bug. Look at the code of the createGetter method:

        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;
        }

If the associated model has already been loaded, all callbacks are called indiscriminately.

You can use the following workaround, as we see that the second argument is not called for cached instances:

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)
        }
    }
});

这篇关于Sencha Touch 2:belongsTo关联回调用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆