谁可以帮助我如何扩展extjs组件使用extjs版本4。我正在寻找相同的正确语法。请帮帮我!
发布于 2011-08-30 17:32:13
下面是在ExtJS 4中扩展textfield的示例代码。
除了使用现有的配置和方法之外,这个扩展组件还创建了一个新的config属性,并创建了一个与事件关联的新方法。
component的用途很简单,如果值是必填项,它将以红色显示标签;如果值为readOnly,则修改字段的背景颜色;当聚焦时,还会更改字段的背景颜色。
代码有正确的注释。希望能有所帮助。
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
}发布于 2011-07-13 13:56:01
Ext.define('myApp.Grid', {
extend: 'Ext.Grid',
alias: 'widget.mygrid'
....
....
}现在可以使用xtype:'mygrid‘
发布于 2012-02-01 08:02:12
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);
}
});https://stackoverflow.com/questions/6609275
复制相似问题