kidccc 2009-08-03 15:35
浏览 331
已采纳

关于Ext.extend的困惑

code can run:
[code="java"]
var MyPanel = Ext.extend(Ext.Panel, {
buttons : [{
text : 'button',
handler : Ext.emptyFn()
}],
initComponent : function() {
Ext.apply(this, {
items : [new Ext.Panel()]
});
MyPanel.superclass.initComponent.apply(this, arguments);
}
});
Ext.reg('MyPanel', MyPanel);
[/code]
code error:
[code="java"]
var MyPanel = Ext.extend(Ext.Panel, {
buttons : [{
text : 'button',
handler : Ext.emptyFn()
}],
items : [new Ext.Panel()],
initComponent : function() {
Ext.apply(this, {});
MyPanel.superclass.initComponent.apply(this, arguments);
}
});
Ext.reg('MyPanel', MyPanel);
[/code]
create an instance of MyPanel
[code="java"]
Ext.onReady(function() {
var myPanelA = new MyPanel({
title : 'Panel A'
});

        myPanelA.render(Ext.getBody());
    })

[/code]

我的问题是items这个选项一定要在initComponent里配置吗?为什么?非常感谢

  • 写回答

3条回答 默认 最新

  • iteye_10013 2009-08-03 16:20
    关注

    看了下Ext.Container-items的源码.
    [code="javascript"]
    // private
    initComponent : function(){
    Ext.Container.superclass.initComponent.call(this);

    ...

    /**

    • The collection of components in this container as a {@link Ext.util.MixedCollection}
    • @type MixedCollection
    • @property items
      */
      var items = this.items;
      if(items){
      delete this.items;
      if(Ext.isArray(items) && items.length > 0){
      this.add.apply(this, items);
      }else{
      //报错的地方
      this.add(items);
      }
      }
      },

      // private 应该是因为这句还没执行
      initItems : function(){
      if(!this.items){
      this.items = new Ext.util.MixedCollection(false, this.getComponentId);
      this.getLayout(); // initialize the layout
      }
      },
      // private
      setLayout : function(layout){
      if(this.layout && this.layout != layout){
      this.layout.setContainer(null);
      }
      //直到这里才执行
      this.initItems();
      this.layout = layout;
      layout.setContainer(this);
      }

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区