暂时还不会用Ext.mixin.Observable,
催悲的测试了近两个小时。这TMD的语法差距也太大了啊。。
在新版EXTJS里,已去除了addEvents。
弄个出来,大概知道下吧。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <! DOCTYPE html> < html > < head > < title >ExtJs</ title > < meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> < link rel="stylesheet" type="text/css" href="ExtJs/packages/ext-theme-crisp/build/resources/ext-theme-crisp-all.css"> < script type="text/javascript" src="ExtJs/ext-all.js"></ script > < script type="text/javascript" src="ExtJs/bootstrap.js"></ script > < script type="text/javascript" src="ExtJs/packages/ext-theme-crisp/build/ext-theme-crisp.js"></ script > < script type="text/javascript"> Ext.onReady(function(){ var name=Ext.extend(Ext.util.Observable,{ constructor:function(config){ this.name=config.name; this.id=config.id; //this.addEvents("fire","quite"); this.listeners=config.listeners; name.superclass.constructor.call(this,config); } }); var username=new name({ name:"Test", id:"001", listeners:{ "fire":function(){alert(username.name);} } }); Ext.get('walk').on('click', function() { username.fireEvent('fire'); }); }); </ script > </ head > < body style="margin: 20px"> < button id="walk">walk</ button > < button id="eat">eat</ button > < button id="sleep">sleep</ button > </ body > </ html > |