响应事件:
1.设置一个html标记
<div id="my-div">Ext JS 4 Cookbook</div>
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(), 500, listeners: { afterrender: function(){ alert('The Panel is rendered!'); }, scope: this } });
6.也能够通过代理的方式。将事件响应绑定到子对象中
var whatsNewEl = Ext.get('whats-new'); <span style="font-family: Arial, Helvetica, sans-serif;">whatsNewEl.on('click', function(e, target, options){ </span><span style="font-family: Arial, Helvetica, sans-serif;">alert(target.innerHTML);</span>
}, 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) });