您的位置:首页 > 其它

创造自己的xtype

2008-07-13 00:17 211 查看
在Ext组件中经常用到grid,form等,在这些组件的items中会出现xtype这样的东西,经常用到的比如说textfield,numberfield,datafield等等,但是能不能使用自己定义的xtype呢,显然是能的,从ext官方上面找到了答案。 现在要创建一个自己的xtype : 'personalgrid',是一种自定义的grid,希望在其他组件中按照如下的方式使用。

var win = new Ext.Window({

title:'Personnel'

,width:600

,height:400

,items:{xtype:'personnelgrid'}

});

win.show();

personnelgrid并不是Ext预置的xtype类型,怎么才能让Ext正确引用呢,就需要编写以下代码:

Application.PersonnelGrid = Ext.extend(Ext.grid.GridPanel, {

border:false

,initComponent:function() {

Ext.apply(this, {

store:new Ext.data.Store({...})

,columns:[{...}, {...}]

,plugins:[...]

,viewConfig:{forceFit:true}

,tbar:[...]

,bbar:[...]

});

Application.PersonnelGrid.superclass.initComponent.apply(this, arguments);

} // eo function initComponent

,onRender:function() {

this.store.load();

Application.PersonnelGrid.superclass.onRender.apply(this, arguments);

} // eo function onRender

});

Ext.reg('personnelgrid', Application.PersonnelGrid);

在这里,我们扩展了Ext.form.GridPanel,创建了一个新的类Application.PersonnelGrid。然后又使用Ext.reg()把这个新的类注册为新的xtype,就是这么简单便捷!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: