Ext4.0 里, 有关如何定义和使用类

1.)直接或间接继承自 Ext.Component的类
例如:
Ext.define('Tyds.Datetime', {
 extend: 'Ext.panel.Panel',
 kind: null,
 textname1: null,
 textname2: null,
 initComponent: function() {  
     if (!this.kind) {
    alert("必须提供你需要的控件类型");
      }
      if (!this.textname1) {
    alert("必须提供输入框名");
      } 
      if (!this.textname2 && (this.kind == "fromto" ||this.kind == "selectmonth" ||this.kind == "selectji" )) {
    alert("必须提供第二个输入框名");
      }  
      Ext.apply(this, {
       items: [{
             xtype: 'datefield',
             name : this.textname1,
             fieldLabel:this.textname1
            },{
             xtype: 'textfield',
             name : this.textname2,
             fieldLabel: this.textname2
              }]
       });
      this.callParent();      
  }
 })

调用:var tt=Ext.create( 'Tyds.Datetime', {kind:"fromto", textname1:"tyd1",  textname2:"tyd22", renderTo: Ext.getBody()});

 

2)直接或间接继承自 非Ext.Component的类

因为只有直接或间接继承自 Ext.Component的类才会在constructor里调用initComponent方法。所以这时initComponent()这个方法不会在构造时执行。所以,只能以下三种方式之一构建:

 

例如:
1. Ext.define('Tyds.Datetime', {
 constructor : function(){
  this.superclass.constructor.call(this, {kind:"kk", textname1:"t1", textname2:"2kk" })
 }
})
调用:var tt=Ext.create( 'Tyds.Datetime');

 

2. Ext.define('Tyds.Datetime', {
 constructor : function(config){
  this.superclass.constructor.call(this, config)
 }
})
调用:var tt=Ext.create( 'Tyds.Datetime', {kind:"fromto", textname1:"tyd1",  textname2:"tyd22"});

 

3.Ext.define('Tyds.Datetime', {
 kind: null,
 textname1: null,
 textname2: null,
 constructor : function(config){
        this.kind = config.kind;
        this.textname1 = config.textname1;
        this.textname2 = config.textname2;
 }
})
调用:var tt=Ext.create( 'Tyds.Datetime', {kind:"fromto", textname1:"tyd1",  textname2:"tyd22");


Ext4.0 <wbr>里, <wbr>有关如何定义和使用类!在一系列的继承中要注意的是,如果重写了构造函数,则应该在必要的时候调用超类(superclass)的构造函数,initComponent和onRender也一样。否则可能会造成一些不必要的麻烦。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值