首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ExtJs 4...如何扩展Extjs4组件?

问ExtJs 4...如何扩展Extjs4组件?
EN

Stack Overflow用户
提问于 2011-07-07 18:35:52
回答 4查看 29.6K关注 0票数 20

谁可以帮助我如何扩展extjs组件使用extjs版本4。我正在寻找相同的正确语法。请帮帮我!

EN

回答 4

Stack Overflow用户

发布于 2011-08-30 17:32:13

下面是在ExtJS 4中扩展textfield的示例代码。

除了使用现有的配置和方法之外,这个扩展组件还创建了一个新的config属性,并创建了一个与事件关联的新方法。

component的用途很简单,如果值是必填项,它将以红色显示标签;如果值为readOnly,则修改字段的背景颜色;当聚焦时,还会更改字段的背景颜色。

代码有正确的注释。希望能有所帮助。

代码语言:javascript
复制
Ext.define('Ext.pnc.Textfield', {

extend: 'Ext.form.field.Text',//Extending the TextField

alias: 'widget.pnctextfield',//Defining the xtype

config:{
    focusCls:'focusClassFieldPnC',//Providing value for existing config property.
    testConfig:'testConfigValue'//Creating a new config. Accessor functions will be created for this one by ExtJS engine
},

constructor:function(cnfg){
    this.callParent(arguments);//Calling the parent class constructor
    this.initConfig(cnfg);//Initializing the component
    this.on('beforerender',this.beforeRender);//Associating a new defined method with an event
},

//Defining a method below and associating this with an event in the constructor above
beforeRender:function(){

    if(!this.allowBlank){
        this.labelStyle =   'color:#FF0000';        
    }

    if(this.readOnly){
        this.fieldCls   =   'readOnlyClass';
    }
},

//Over-riding a function which already exists in parent class. Note that this has not been associated with any event in constructor as it already defined in parent class
afterRender:function(){
    console.log('after render function');
    this.callParent();//Calling the parent class method. This can be omitted if not     required and is not a must
}
});

.readOnlyClass{
background:#FF0000 !important
}


.focusClassFieldPnC{
background:#00ff00 !important
}
票数 23
EN

Stack Overflow用户

发布于 2011-07-13 13:56:01

代码语言:javascript
复制
Ext.define('myApp.Grid', {
        extend: 'Ext.Grid',
        alias: 'widget.mygrid'
        ....
        ....
        }

现在可以使用xtype:'mygrid‘

票数 7
EN

Stack Overflow用户

发布于 2012-02-01 08:02:12

代码语言:javascript
复制
Ext.define('BS.view.MyGrid' , {
    extend: 'Ext.grid.Panel',
    alias: 'widget.my-grid',

    // Non-complex config types (booleans, integers, strings) go here
    width: 1000,
    autoHeight: true

    initComponent: function() {
        Ext.apply(this, {
            // complex configs (objects / arrays) go here
            columns: colModel,  
        });

        this.callParent(arguments);
    }
});
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6609275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档