暂时还不会用Ext.mixin.Observable,
催悲的测试了近两个小时。这TMD的语法差距也太大了啊。。
在新版EXTJS里,已去除了addEvents。
弄个出来,大概知道下吧。
<!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>
时间: 2024-10-07 13:56:06