我经常在我正在制作的应用程序中使用它,所以如果可以的话,我想缩短它并制作一个扩展类来在一个地方处理所有回调逻辑,我尝试像这样设置它但尝试时失败加载类:
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
});
更新 这是有道理的,我不敢相信忽略了这一点,但我仍然得到上面未定义错误的相同读取属性“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);
}
});