0

自分が作っているアプリでよく使うので、できれば短くして、すべてのコールバックロジックを一か所で処理できる拡張クラスを作りたいと思います。このように設定してみましたが、失敗しました。次のクラスをロードします。

Uncaught TypeError: Cannot read property 'isInstance' of undefined ext-all-debug.js:4136
ExtClass.registerPreprocessor.config ext-all-debug.js:4136
Ext.apply.doProcess ext-all-debug.js:4007
Manager.registerPostprocessor.uses ext-all-debug.js:6037
Ext.apply.require ext-all-debug.js:5771
Manager.registerPostprocessor.uses ext-all-debug.js:6004
Ext.apply.doProcess ext-all-debug.js:4007
Ext.apply.doProcess ext-all-debug.js:4008
Ext.apply.process ext-all-debug.js:3995
Ext.Class.ExtClass ext-all-debug.js:3911
Ext.ClassManager.create ext-all-debug.js:4676
Ext.apply.define ext-all-debug.js:5095
(anonymous function) Ajax.js:1 //My extended Ajax singleton

これが私がそれを呼ぼうとする方法です

    var changes = e.record.getChanges();
    if (e.record.get('id'))
        changes.id = e.record.get('id');

    APP.ux.Ajax.request({
        url: '/admin/user/save/',
        params: changes,
        scope: this
    });

UPDATE それは理にかなっています、私はそれを見落としたとは信じられませんが、それでも上記の未定義のエラーの同じ読み取りプロパティ'isInstance'を取得します。これが今の様子です

そして、これが単純なクラスです(更新)

Ext.define('APP.ux.Ajax', {
extend: 'Ext.data.Connection',
requires: [
    'APP.ux.Msg'
],
singleton : true,
autoAbort : false,
request: function(config) {
    var cfg = config;

    Ext.apply(cfg, {
        success: function(form, action) {
            APP.ux.Msg.alert('Success', action.result.msg);
            //TODO: Add more logic here
        },
        failure: function(form, action) {
            switch (action.failureType) {
                case Ext.form.action.Action.CLIENT_INVALID:
                    APP.ux.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
                    break;
                case Ext.form.action.Action.CONNECT_FAILURE:
                    APP.ux.Msg.alert('Failure', 'Ajax communication failed');
                    break;
                case Ext.form.action.Action.SERVER_INVALID:
                    APP.ux.Msg.alert('Failure', action.result.msg);
                    break;
            }
        }
    });
    this.callParent(cfg);
}
});
4

1 に答える 1

1

このままではうまくいかない。失敗/成功ハンドラーを 1 か所に配置したい場合は、標準request()メソッドを次のように上書きする必要があります (これは App.ux.Ajax クラスに移動します)。

request: function(config) {
  var cfg = config;

  Ext.apply(cfg, {
    success: function(form, action) {
       APP.ux.Msg.alert('Success', action.result.msg);
       //TODO: Add more logic here
    },
    failure: function(form, action) {
       switch (action.failureType) {
        case Ext.form.action.Action.CLIENT_INVALID:
            APP.ux.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
            break;
        case Ext.form.action.Action.CONNECT_FAILURE:
            APP.ux.Msg.alert('Failure', 'Ajax communication failed');
            break;
        case Ext.form.action.Action.SERVER_INVALID:
            APP.ux.Msg.alert('Failure', action.result.msg);
            break;
       }
    }
  });

  this.callParent(cfg);
}
于 2012-06-14T15:25:30.710 に答える