有人可以帮助我如何使用extjs版本4扩展extjs组件。我正在寻找适当的语法。请帮忙.. !!
答案 0 :(得分:22)
以下是在ExtJS 4中扩展文本字段的示例代码。
除了使用现有的配置和方法之外,此扩展组件还创建了一个新的配置属性,并创建了一个新的方法。与事件相关联。
组件的用途很简单,如果值是必需的,它会以红色显示标签,如果是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
}
答案 1 :(得分:7)
Ext.define('myApp.Grid', {
extend: 'Ext.Grid',
alias: 'widget.mygrid'
....
....
}
现在你可以使用xtype:'mygrid'
答案 2 :(得分:6)
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);
}
});
答案 3 :(得分:5)
为什么不看到extjs4的组件的src,如Grid,Table ......
以下是文档:
http://docs.sencha.com/ext-js/4-0/#/guide/components< ==重要
http://docs.sencha.com/ext-js/4-0/#/guide/class_system
Ext.define('My.custom.Component', {
extend: 'Ext.Component'
});