【问题标题】:Sencha Touch 2: belongsTo association callback usage?Sencha Touch 2:belongsTo 关联回调用法?
【发布时间】:2013-06-12 18:35:43
【问题描述】:

我调用了一个 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 没有多大帮助。

【问题讨论】:

    标签: extjs sencha-touch-2


    【解决方案1】:

    肯定是一个错误。看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)
            }
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多