日期:2014-05-16  浏览次数:20452 次

ExtJs 继承写法
小弟做个笔记,以便后期使用:
1.继承写法
com.wangdl.cn.MyPanel = function(){
    //构造器中调用父类构造,传参
    com.wangdl.cn.MyPanel.superclass.constructor.call(this,{
        title:'hello',
        tbar:[
		{
		text:'adduser',
		handler:this.addUser,
		scope:this//加这一行可以使addUser方法执行的环境发生变化
		}
	]
	});	
};
//通过第三个参数指定调用父类initComponent方法,并在并列的位置定义自己的方法
Ext.extend(com.wangdl.cn.MyPanel,Ext.Panel,{
	initComponent:function(){
		//Ext.apply(this);
		com.wangdl.cn.MyPanel.superclass.initComponent.call(this);
	},
	addUser:function(){
		alert(this.title);
	}
});

2.第二种写 法
com.wangdl.cn.MyPanel = Ext.extend(Ext.Panel,{
	title:'test hello',
	initComponent:function(){
		Ext.apply(this,{
			tbar:[
			{text:'addUser',handler:this.addUser,scope:this}
			]
		});
		com.wangdl.cn.MyPanel.superclass.initComponent.call(this);
	},
	addUser:function(){
		alert(this.title);
	}
});