我有一个带有'卡'布局的MainView有2个项目:MenuView和TestView。当我为MenuView设置setActive时,它的宽度等于MainView的宽度为1280.在menuView中点击一个按钮后的下一个动作中,我将setActive设置为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);
}
});
答案 0 :(得分:0)
您可以使用setWidth();
设置宽度Test.views.testView.setWidth('50px');