Extjs setactiveitem只工作一次
我的问题是我有3个视图文件和一个控制器 以下是3个按钮点击事件的代码Extjs setactiveitem只工作一次,extjs,sencha-touch-2,Extjs,Sencha Touch 2,我的问题是我有3个视图文件和一个控制器 以下是3个按钮点击事件的代码 onb1:function(){ Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true); Ext.Viewport.add({xtype:'second',height:'30%',style:'background:red'}).show(); }, onb3:function(){ Ext.Viewport.remove(Ext.V
onb1:function(){
Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
Ext.Viewport.add({xtype:'second',height:'30%',style:'background:red'}).show();
},
onb3:function(){
Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
Ext.Viewport.add({xtype:'main'}).show();
},
onb2:function(){
Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
Ext.Viewport.add({xtype:'third',height:'60%',style:'background:orange'}).show();
}
它只工作一次
告诉我任何解决方案…第一次自动设置activeItem。之后,你必须自己设置。也不需要调用show()。应该这样做:
Ext.Viewport.add(someView);
Ext.Viewport.setActiveItem(someView);
Ext.define('mybutton',{
extend: 'Ext.Button',
config: {
text: 'my button'
},
initialize: function(){
var me = this;
this.addListener({
fn: me.doSmt,
event: 'tap'
});
}
doSmt: function(){
// implement your logics here.......
}
});
原因是,这行代码:
Ext.Viewport.remove(Ext.Viewport.getActiveItem(),true)代码>
将删除您的组件,然后将其销毁
也许您必须定义处理程序,使它们仅在定义时绑定到这些组件,而不是在初始化时绑定到这些组件
因此,如果不在频繁添加/删除的组件的initialize
方法中声明处理程序函数
表示组件是按钮,因此定义文件应如下所示:
Ext.Viewport.add(someView);
Ext.Viewport.setActiveItem(someView);
Ext.define('mybutton',{
extend: 'Ext.Button',
config: {
text: 'my button'
},
initialize: function(){
var me = this;
this.addListener({
fn: me.doSmt,
event: 'tap'
});
}
doSmt: function(){
// implement your logics here.......
}
});
谢谢,但是我的应用程序已经填充了id引用,我将收到以下错误:Ext.Component#constructor]注册一个id为(first
)的组件,该id已被使用。请确保现有组件已被销毁(Ext.component#destroy()
。在不更改id的情况下,任何解决方案都可以发布组件的代码吗?此外,建议使用ItemId,而不是使用指定的id。更多信息请参见此处: