在写拓展组件之前,我们先要搞清楚“插件”(Plugin)和“组件”(Component)的区别。(引用自其它博客:http://blog.csdn.net/jerrysbest/article/details/6655417)
- 一个扩展就是一个新名字出现的一个新类,它是以某个基类为基础,属于类库中的一员。扩展必须好像其他类那样实例化般地使用。
- 插件被插入到现有的某个类之中,可灵活地移除,它可以在类库中定义,然后伴随某个类实例化的时候参与运作。
好,就拿一个extend xtype"compositefield"为例:
- FaxPhoneCompositeField = Ext.extend(Ext.form.CompositeField,{
- initComponent: function() {
- Ext.apply(this,{
- items:[
- {
- xtype : 'textfield',
- flex : 1
- },{
- xtype: 'displayfield',
- value: '-',
- },
- {
- xtype : 'textfield',
- flex : 1
- },{
- xtype: 'displayfield',
- value: '-'
- },
- {
- xtype : 'textfield',
- flex : 1
- }
- ],
- labelWidth: 220
- });
- FaxPhoneCompositeField.superclass.initComponent.apply(this);
- }
- });
- Ext.reg('FaxPhoneCompositeField',FaxPhoneCompositeField);
就这样子就定义了一个xtype为“FaxPhoneCompositeField”的拓展组件
然后我们可以在我们的其他地方使用它:
- Ext.onReady(
- function(){
- var f=new Ext.form.FormPanel({
- title:"test",
- width:600,
- height:150,
- bodyStyle:"padding:6px",
- labelAlign:'left',
- layout:'form',
- frame:true,
- items: [{
- xtype: 'FaxPhoneCompositeField',
- id:'phone',
- fieldLabel: 'Fax',
- }]
- });
- f.render(Ext.getBody());
效果如下:
转载于:https://blog.51cto.com/6221123/1073169