ExtJS學習筆記2:響應事件、使用AJAX載入資料

來源:互聯網
上載者:User

ExtJS學習筆記2:響應事件、使用AJAX載入資料

響應事件:

1.設定一個html標記

Ext JS 4 Cookbook

2.使用get函數擷取此標記對象

var el = Ext.get('my-div');

3.將響應函數和對象的事件綁定

el.on('click', function(e, target, options){alert('The Element was clicked!');alert(this.id);}, this);

4.一次也可綁定多個事件

el.on({click: function(e, target, options){alert('The Element was clicked!);alert(this.id);},contextmenu: function(e, target, options){alert('The Element was right-clicked!');alert(this.id);},scope: this});

5.也可在建立extjs對象時,在配置中使用listeners配置屬性設定

Ext.create('Ext.panel.Panel', {title: 'Ext JS 4 Cookbook',html: 'An Example Panel!',renderTo: Ext.getBody(),width: 500,listeners: {afterrender: function(){alert('The Panel is rendered!');},scope: this}});

6.也可以通過代理的方式,將事件響應綁定到子物件中

var whatsNewEl = Ext.get('whats-new');whatsNewEl.on('click', function(e, target, options){alert(target.innerHTML);
}, this, {delegate: 'li'});

使用AJAX載入資料

Ext.Ajax.request({url: 'url',
params:{},//參數success: function(response, options){//成功擷取資料後的處理},failure: function(response, options){//失敗},callback: function(options, success, response){//回呼函數},timeout: 60000 //60 seconds (default is 30)});


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.