如何在单击删除按钮时从ExtJS中删除活动选项卡?

huangapple go评论55阅读模式
英文:

How can I remove an active tab in ExtJS when clicking on a delete button?

问题

如何移除添加的选项卡?
我想在单击删除按钮时移除活动选项卡。

var tabs = Ext.create('Ext.tab.Panel',{
    items: [{
        // id:0
        title:'tab1',
        html:'text to tab1'
    },{
        // id:2
        title:'tab2',
        html:'text to tab2'
    }],
    renderTo: Ext.getBody()
});

Ext.create('Ext.button.Button',{
    text:'add',
    style:{backgroundColor: 'green'},
    handler: function(){
        var tab = tabs.add({
            // id: tabs.items[1].id + 1,
            title: 'tab' +  (tabs.items.length + 1),
            html: 'new tab ' + (tabs.items.length + 1)
        });
        tabs.setActiveTab(tab);
    },
    renderTo:Ext.getBody()
});

Ext.create('Ext.button.Button', {
    text:'del',
    style:{backgroundColor:'red'},
    handler: function(){
        // ...  
    },
    renderTo: Ext.getBody(),
})

img

根据我看到的解决方案:
我需要为每个选项卡动态分配一个ID,然后在事件处理程序中使用循环。
如果是这样,如何实现?

英文:

How to remove added tab?
I want to remove the active tab on click on delete.

var tabs = Ext.create('Ext.tab.Panel',{
    items: [{
        // id:0
        title:'tab1',
        html:'text to tab1'
    },{
        // id:2
        title:'tab2',
        html:'text to tab2'
    }],
    renderTo: Ext.getBody()
});

Ext.create('Ext.button.Button',{
    text:'add',
    style:{backgroundColor: 'green'},
    handler: function(){
        var tab = tabs.add({
            // id: tabs.items[1].id + 1,
            title: 'tab' +  (tabs.items.length + 1),
            html: 'new tab ' + (tabs.items.length + 1)
        });
        tabs.setActiveTab(tab);
    },
    renderTo:Ext.getBody()
});

Ext.create('Ext.button.Button', {
    text:'del',
    style:{backgroundColor:'red'},
    handler: function(){
        // ...  
    },
    renderTo: Ext.getBody(),
})

img

As I see the solution:
I need to dynamically assign an id to each tab and then use a loop in the event handler.
If so, how to implement?

答案1

得分: 2

你可以通过tabPanel.getActiveTab()获取当前活动的选项卡,然后可以从tabPanel中移除它。tabPanel.remove(activeTab)。

我希望这个示例链接对你有所帮助 https://fiddle.sencha.com/#view/editor&fiddle/3o0f

英文:

you can get the active Tab by tabPanel.getActiveTab(), and then you can remove it from the tabPanel. tabPanel.remove(activeTab).

I hope this fiddle will help you https://fiddle.sencha.com/#view/editor&fiddle/3o0f

huangapple
  • 本文由 发表于 2023年5月24日 21:22:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76324024.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定