问题描述
这是用ext designer 自动生成的代码,我想讲items里json格式panel定义直接用panel类名替代,不知可不可行。MyViewportUi = Ext.extend(Ext.Viewport, { layout: 'border', initComponent: function() { this.items = [ { xtype: 'panel', title: 'My Panel', region: 'center' }, {[color=red][/color] xtype: 'panel', title: 'My Panel', region: 'west', width: 100 }, { xtype: 'panel', title: 'My Panel', region: 'east', width: 100 } ]; MyViewportUi.superclass.initComponent.call(this); }});以下是ext designer 生成的viewport和panel的类定义viewport定义MyViewportUi = Ext.extend(Ext.Viewport, { layout: 'border', initComponent: function() { this.items = [ { xtype: 'panel', title: 'My Panel', region: 'center' }, { xtype: 'panel', title: 'My Panel', region: 'west', width: 100 }, { xtype: 'panel', title: 'My Panel', region: 'east', width: 100 } ]; MyViewportUi.superclass.initComponent.call(this); }});panel定义MyPanelUi = Ext.extend(Ext.Panel, { title: 'My Panel', region: 'center', initComponent: function() { MyPanelUi.superclass.initComponent.call(this); }});MyPanel1Ui = Ext.extend(Ext.Panel, { title: 'My Panel', region: 'west', width: 100, initComponent: function() { MyPanel1Ui.superclass.initComponent.call(this); }});MyPanel2Ui = Ext.extend(Ext.Panel, { title: 'My Panel', region: 'east', width: 100, initComponent: function() { MyPanel2Ui.superclass.initComponent.call(this); }});我的想法是viewport中items不用json格式了,而是直接用panel的类名定义,如下面代码所示,不知可行,可有类似方法?MyViewportUi = Ext.extend(Ext.Viewport, { layout: 'border', initComponent: function() { this.items = [ MyPanelUi, MyPanel1Ui, MyPanel2Ui ]; MyViewportUi.superclass.initComponent.call(this); }}); 问题补充:lizhi92574 写道
解决方案
对。
解决方案二:
js 是顺序执行的,明白你就清楚了。你可以写在 Ext.onReady(function(){});//函数里就行了。该函数等body加载完成才执行
解决方案三:
恩,不过你在使用MyViewportUi的时候必须要保证MyPanelUi要被加载了。
解决方案四:
不行,必须加 new this.items = [ new MyPanelUi(), new MyPanel1Ui(), new MyPanel2Ui() ];