extjs 4同一组件多个选项卡
我正在使用 extjs 4 & Rails 3.我有工具栏和选项卡面板。我想在所有选项卡面板和选项卡中使用相同的工具栏希望工具栏上的按钮根据活动的选项卡工作。例如。工具栏包含添加、编辑等按钮。假设我有区域和类别选项卡。当区域选项卡处于活动状态时,我应该能够对“区域”和“区域”执行“添加”操作。很快。在 extjs 4 中实现这一目标的正确方法是什么?我无法在“区域”和“区域”中的工具栏上分配操作类别控制器? 我提到这个但不知道如何实现它在我的代码中吗? 这是我尝试过的“Regions”extjs mvc 控制器的示例代码。问题是,如果我在 Category 控制器中为 commontoolbar 的 ADD btn 编写类似的代码,则会调用 Region 的 ADD 实现:(
Ext.define('overdrive.controller.Regions', {
extend: 'Ext.app.Controller',
views: [
'region.RegionList',
'region.RegionForm',
'region.RegionPanel',
'common.CommonToolbar'
],
models: ['Region'],
stores: ['Regions'],
init: function() {
this.control({
'viewport > panel': {
render: this.onPanelRendered
},
'regionpanel':{
beforerender:this.addToolbar
} ,
'commontoolbar button[action=chk]': {
click: this.chk
}
});
},
chk:function()
{
var tabcon = Ext.getCmp('tabcon');//tabcon is id of tab panel
var activetab = tabcon.getActiveTab();
var activetabid = activetab.getId();
console.log('Active Tab ID:'+activetabid);
if(activetabid == 'regiontab'){
alert('Clicked button in region Tab');
}else if(activetabid == 'storetab'){
alert('Clicked button in store Tab');
}
},
addToolbar:function()
{
var regionpanel=Ext.widget('regionpanel');
var regiontab=Ext.getCmp('regiontab');
var tabcon = Ext.getCmp('tabcon');
regiontab.add({
xtype:'commontoolbar', id:'regiontoolbar',
itemId: 'regiontoolbar'
});
},
addRegion: function(button) {
var regiontoolbar=button.up('regiontoolbar');
var regiontab = Ext.getCmp('regiontab');
var regionpanel = regiontab.down('regionpanel');
var regionform = regionpanel.down('regionform');
regiontoolbar.child('#add').setDisabled(true);
regiontoolbar.child('#edit').setDisabled(true);
regiontoolbar.child('#delete').setDisabled(true);
regiontoolbar.child('#save').setDisabled(false);
regiontoolbar.child('#cancel').setDisabled(false);
regionpanel.layout.setActiveItem(regionform);
}
});
i m working with extjs 4 & rails 3. i am having toolbar & tab panel. i want to use same toolbar in all the tab panel & want buttons on the toolbar to work according to tab that is active. For eg. toolbar contains add,edit,etc buttons. Suppose i have region & category tabs. When region tab is active i should be able to perform "ADD" operation for "Region" & so on. What can be the correct way to achieve this in extjs 4 ? I am not able to assign action on toolbar in Region & Category controllers?
i referred thisbut no idea as to how can i implement it in my code ?
Here is sample code of "Regions" extjs mvc controller that i have tried. The problem is if i write similar code in Category contoller for ADD btn of commontoolbar, ADD implementation of Region gets called :(
Ext.define('overdrive.controller.Regions', {
extend: 'Ext.app.Controller',
views: [
'region.RegionList',
'region.RegionForm',
'region.RegionPanel',
'common.CommonToolbar'
],
models: ['Region'],
stores: ['Regions'],
init: function() {
this.control({
'viewport > panel': {
render: this.onPanelRendered
},
'regionpanel':{
beforerender:this.addToolbar
} ,
'commontoolbar button[action=chk]': {
click: this.chk
}
});
},
chk:function()
{
var tabcon = Ext.getCmp('tabcon');//tabcon is id of tab panel
var activetab = tabcon.getActiveTab();
var activetabid = activetab.getId();
console.log('Active Tab ID:'+activetabid);
if(activetabid == 'regiontab'){
alert('Clicked button in region Tab');
}else if(activetabid == 'storetab'){
alert('Clicked button in store Tab');
}
},
addToolbar:function()
{
var regionpanel=Ext.widget('regionpanel');
var regiontab=Ext.getCmp('regiontab');
var tabcon = Ext.getCmp('tabcon');
regiontab.add({
xtype:'commontoolbar', id:'regiontoolbar',
itemId: 'regiontoolbar'
});
},
addRegion: function(button) {
var regiontoolbar=button.up('regiontoolbar');
var regiontab = Ext.getCmp('regiontab');
var regionpanel = regiontab.down('regionpanel');
var regionform = regionpanel.down('regionform');
regiontoolbar.child('#add').setDisabled(true);
regiontoolbar.child('#edit').setDisabled(true);
regiontoolbar.child('#delete').setDisabled(true);
regiontoolbar.child('#save').setDisabled(false);
regiontoolbar.child('#cancel').setDisabled(false);
regionpanel.layout.setActiveItem(regionform);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
希望以下代码对您有所帮助:
您可以通过单击以下链接查看上述代码的工作示例:
http:// /jsfiddle.net/kVbra/23/
1.打开上述链接后,您可以在右下角找到结果。
2.根据您的问题,创建了一个工具栏,并在具有相同按钮的两个选项卡中使用。
3.如果单击该按钮,它将获取当前选项卡 ID,并根据激活的选项卡显示不同的结果。
Hope the following code will help you:
You can check the working sample of above code by clicking the following link:
http://jsfiddle.net/kVbra/23/
1.After opening the above link you can find the result in right bottom corner.
2.As per your question one toolbar is created and it is using in two tabs with same button.
3.If you click on the button,then it will get the current tab id and it will display the different result as based on which tab is activated.
如果您严格只使用一个类,下面的代码可能对您也有帮助:
工作示例:
http://jsfiddle.net/kesamkiran/kVbra/30/
If you are strict to use only one class,may be the below code also helpful for you shruti:
Working sample:
http://jsfiddle.net/kesamkiran/kVbra/30/