创造自己的xtype

在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,就是这么简单便捷!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值