The last one we have a simple understanding of the next TabPanel
Below we want to introduce is, how to add the tab page dynamically!
2. Dynamically add a TabPanel label page
Effect Chart:
Clicking on "Add new tab" will add a tab and activate the New tab page.
HTML code:
<body style= "margin:10px;" >
<div>
<a id= "Addnewtab" href= "javascript:void (0)" > Add new Tab </a>
</div>
</body>
JS Code:
Ext.onready (function () {
Ext.QuickTips.init ();
var tabsdemo=new ext.tabpanel ({
RenderTo:Ext.getBody (),
activetab:0,
height:700,
Frame:true,
items:[{
Title: "AutoLoad for HTML Simple page demo",
Autoload:{url: "Tab1.htm", scripts:true}
}]
});
Here is the key code to add a new tab, very simple and convenient
var index=0;
Ext.get ("Addnewtab"). On ("click", Function () {
Tabsdemo.add ({
Title: "Newtab",
ID: "Newtab" +index,
HTML: "New Tab",
Closable:true
});
Tabsdemo.setactivetab ("Newtab" +index);
index++;
})
});
Simple description:
Actually add, as long as the Add () method is OK, but we also want to activate the new tab, we must SetActiveTab (Newtab index or ID), the key is that we do not judge the index, So we have to set an incremental global variable index to give Newtab name, so we can accurately obtain new newtab, also easy to activate. And we can see it through the figure below.
3. Slightly revise the above example TabPanel (official example)
Effect Chart: