我有一个带有“卡片”布局的 MainView 有 2 项:MenuView 和 TestView。当我为 MenuView 设置 Active 时,它的宽度等于 MainView 的宽度,即 1280。在点击 menuView 中的按钮后的下一个操作中,我设置了 TestView,但它的宽度仅为 0。谁能为我解释一下?并给我一种将TestView的宽度设置为1280的方法。这是我在sencha touch 1中的代码:
'Ext.regController('MainController',{
'index': function(options){
if (!Test.views.mainView){
Test.views.mainView = new Test.views.MainView();
}
console.log('mainView width: '+ Test.views.mainView.getWidth());
console.log('menuView width: '+ Test.views.menuView.getWidth());
Test.views.mainView.setActiveItem(Test.views.menuView);
},
'start': function(options){
console.log('testView width: '+ Test.views.testView.getWidth());
Test.views.mainView.setActiveItem(Test.views.testView);
}
});
Test.views.MainView = Ext.extend(Ext.Panel, {
fullscreen : 'true',
layout : 'card',
cardSwitchAnimation : 'slide',
initComponent : function (){
Ext.apply(Test.views, {
menuView: new Test.views.MenuView(),
testView: new Test.views.TestView()
});
this.items = [Test.views.menuView, Test.views.testView]
Test.views.MainView.superclass.initComponent.call(this);
}
});
Test.views.MenuView = Ext.extend(Ext.Panel,{
initComponent: function(){
this.startButton = new Ext.Button({
text: 'Start',
ui: 'action',
scope: this,
handler: function(){
Ext.dispatch({
controller: Test.controllers.mainController,
action: 'start'
});
}
});
this.exitButton = new Ext.Button({
text: 'Exit',
ui: 'action',
scope: this,
handler: function(){
}
});
this.items = [this.startButton, this.exitButton]
Test.views.MenuView.superclass.initComponent.call(this);
}
});
Test.views.TestView = Ext.extend(Ext.Panel,{
initComponent: function(){
this.html = 'test';
Test.views.TestView.superclass.initComponent.call(this);
}
});