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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog