---
title: "extjs扩展自己的组件"
author: "minzaipiao"
date: "2009-06-16T09:40:07Z"
tags: ["EXT", "prototype"]
categories: ["Web前端"]
slug: "extjs"
draft: false
lastmod: "2009-12-31T11:45:16Z"
id: 409113
url: "https://dengm1010.iteye.com/blog/409113"
---

```js

myWindow = function(cfg){
	Ext.apply(this,cfg); //属性拷贝,apply将会覆盖目标对象中的属性
	Ext.onReady(this.init, this);
}

Ext.extend(myWindow, Ext.util.Observable,{
	init: function(){
		
		this.formPanel = new Ext.form.FormPanel({
			width:280,
			height:280,
			labelWidth:50,
			frame:true,
			defaultType:'textfield',
			items:[
				{
				fieldlabel:'name'
				},
				{fieldlabel:'age'}
			],
			buttons:[
			{text:'add'}
			]
		});
		
		this.showWindow = new Ext.Window({
			width:300,
			height:300,
			title:'坏蛋吧',
			items:[this.formpanel]
		});
		this.showWindow.show();
	}
});

new myWindow();

```




```js

userPanel = Ext.extend(Ext.Window,{
	title:'entend Ext.window',
	width:300,
	height:200,
	buttonAlign:'center',
	layout:'fit',
	initComponent:function(){
		Ext.apply(this,{
			buttons:[{
				text:'new',
				handler:this.saveuser.createdelegate(this)
			},{
				text:'cancel',
				handler:this.cancel.createdelegate(this)
			}]
		}),
		userPanel.superclass.initComponent.call(this),
		this.uf = this.createForm();
		this.add(this.uf);
	},
	createForm:function(){
		var uf = new Ext.form.FormPanel({
			defaultType:'textfield',
			labelAlign:'right',
			labelWidth:50,
			frame:true,
			items:[{
				fieldlabel:'用户名',
				name:'username',
				allowblank:false
			},{
				fieldlabel:'密码',
				name:'password',
				inputtype:'password',
				allowblank:false
			}]
		});
		return uf;
	},
	saveUser:function(){
		if(this.uf.form.isValid())
		{
			alert("hello ");
		}
	},
	cancel:function(){
		alert('cancel');
	}
	
});

Ext.onReady(function(){
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';
	new userPanel().show();
});

```