![](https://img.51dongshi.com/20210302/wz/96762952.jpg)
代碼如下:
var tabIndex = 'shouye';
var tabIndex2 = 'shouye';
var tabIndex3 = 'shouye';
var tabIndex4 = 'shouye';
var tabIndex5 = 'shouye';
var tabIndex6 = 'shouye';
var tabIndex7 = 'shouye';
/**
* 向TabPanel組件中添加窗口或激活已經(jīng)存在的窗口
* 并將指定資源加載進窗口
* @param node : 傳入的Node節(jié)點
*/
var loadPanel = function(node) {
var id= node.id;//獲取節(jié)點的id
tabIndex7 = id;
var href = node.attributes.href;//獲取節(jié)點中的href屬性
var text = node.text;
var mainPanel = Ext.getCmp('mainPanel');
//mainPanel.remove('mainPanel', true);
var qtip = node.attributes.qtip;
var tab = mainPanel.getComponent(String(id));//獲取指定id的組件對象
if(tab) {
mainPanel.setActiveTab(tab);//檢驗當前Tab選項卡是否存在,如果存在只需要激活
return;
}
//如果選項卡不存在,則以下為創(chuàng)建選項卡代碼
tab = mainPanel.add(new Ext.Panel ({
//創(chuàng)建新選項卡的配置
id : String(id),//設(shè)置ID,需強制轉(zhuǎn)換為string類型
title : text,//設(shè)置選項卡標題
tabTip : text,
html : '',
autoScroll: true,
enableTabScroll:true,
defaults: {autoScroll:true},
closable : true //是否可以關(guān)閉
}));
mainPanel.setActiveTab(tab);//創(chuàng)建選項卡后,將其激活
mainPanel.remove(tabIndex, true);
tabIndex = tabIndex2;
tabIndex2 = tabIndex3;
tabIndex3 = tabIndex4;
tabIndex4 = tabIndex5;
tabIndex5 = tabIndex6;
tabIndex6 = tabIndex7;
}
使用的是用變量存儲 id 加載新的選卡時 交換 id ,從而限制了打開的選項卡數(shù)量,如果不是一定要這個效果,建議不要頻繁的關(guān)閉和創(chuàng)建tabpanel
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。