1 /* 2 *tpl模版加入按鈕 3 *<div class="x-button-normal x-button x-iconalign-center x-layout-box-item x-stretched btn" style="visibility:{visibility}" fire="TasteUp" ><span class="x-button-icon x-shown lower"></span></div> 4 *fire="tasteUp" 表示添加tasteUp事件和激活dotasteUp方法 5 *有兩個參數cmp:視圖自己以及doit 6 *只要是以上格式的模板均可以被監控到 7 *其中btn、shareIco爲自定義樣式,其餘都是st自帶樣式 8 */ 9 Ext.define('ux.plugin.ConTpl', { 10 alias: 'plugin.conTpl', 11 xtype: 'conTpl', 12 config: { 13 cmp: null, 14 //按下時添加css 15 pressedCls: 'pressing', 16 //監控對象選擇器 17 delegate: 'div.fire' 18 }, 19 constructor: function (config) { 20 this.initConfig(config); 21 this.callParent([config]); 22 }, 23 //初始化 24 init: function (cmp) { 25 this.setCmp(cmp); 26 }, 27 //更新配置 28 updateCmp: function (newCmp, oldCmp) { 29 if (newCmp) { 30 newCmp.on({ 31 //只有建立完成後才能監聽事件 32 render: 'onRender', 33 scope: this 34 }); 35 } 36 }, 37 //建立完成 38 onRender: function (t, eOpts) { 39 t.el.on({ 40 click: 'onTap', 41 delegate: this.getDelegate(), 42 scope: this 43 }); 44 }, 45 //執行動做 46 onTap: function (e) { 47 var cmp = this.getCmp(), 48 el = e.getTarget(this.getDelegate(), null, true), 49 fire = el.getAttribute('fire'); 50 cmp.fireEvent(fire, cmp, el); 51 } 52 });