2011-11-04 92 views
0

我想在使用Extjs 4编写的自定义类中触发事件。 我使用ExtJs创建了一个自定义类,并从Observable类 扩展,以注册事件。注册自定义事件(Extjs)

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

在costructor我加了登记 '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); 
      } 
     }) 

请avise

+0

也许你会想用'settingWindows.fireEvent'取代'this.fireEvent' –

回答

1

如果Ext.Ajax.request放入您的“设置”类的方法中,只需将范围参数添加到您的E xt.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 
    }) 
+0

非常感谢你。在Ajax调用之前,我分配给了我= this;然后写了范围:我 –