我想在Extjs 4中编写的自定义类中触发事件。
我使用ExtJs创建了一个自定义类,并从Observable类扩展 为了注册活动。
var settingWindows = Ext.define("Setting", {
extend: 'Ext.util.Observable',
title: "",
window: null,
userId: 0,
windowWidth: 650,
windowHeight: 400,
columns: [],
settings: [],
ruleList: [],
isColorPickerOpen: false,
currTrObj: null,
currColorType: null,
constructor: function(config) {
this.windowWidth = config.windowWidth || 650;
this.windowHeight = config.windowHeight || 400;
this.title = config.title || "";
this.userId = config.userId || 0;
this.settings = config.settings || [];
this.CreateWindowSettingsWindows();
this.addEvents('myCustomEvent');
},
});
在constructor
我添加了myCustomEvent
的注册。
在ajax调用中我尝试调用
Ext.Ajax.request({
url: url,
contentType: "application/json",
method: 'POST',
dataType: 'json',
jsonData: Ext.encode(this.settings),
failure: function(response, options) {
Ext.MessageBox.alert(response.statusText);
},
success: function() {
Ext.MessageBox.alert("Data was updated");
this.fireEvent('myCustomEvent', 1);
}
});
请保持
答案 0 :(得分:1)
如果将Ext.Ajax.request放入“Setting”类的方法中,只需将范围参数添加到Ext.Ajax.request调用中:
Ext.Ajax.request({
url: url,
contentType: "application/json",
method: 'POST',
dataType: 'json',
jsonData: Ext.encode(this.settings),
failure: function (response, options) {
Ext.MessageBox.alert(response.statusText);
},
success: function () {
Ext.MessageBox.alert("Data was updated");
this.fireEvent('myCustomEvent', 1);
},
scope: this
})