简体   繁体   English

如何更新ExtJS TabPanel中选项卡的内容?

[英]How can I update the content of a tab in an ExtJS TabPanel?

I have a tab panel like this: 我有一个这样的标签面板:

var tab1 = {
    id: 'section1',
    title: 'First Section',
    padding: 10,
    html: '(this content will be replaced with an ajax load)'
}

var tab2 = {
    id: 'section2',
    title: 'Second Section',
    padding: 10,
    html: '(this content will be replaced with an ajax load)'
}

var tab3 = {
    id: 'section3',
    title: 'Third Section',
    padding: 10,
    html: '(this content will be replaced with an ajax load)'
}

var modules_info_panel = new Ext.TabPanel({
    region: 'center',
    activeTab: 0,
    border: false,
    defaults:{autoScroll:true},
    items:[tab1, tab2, tab3]
});

Then after creating this tabpanel, I would like to dynamically change the content of the tabs, but none of these work: 然后在创建此tabpanel之后,我想动态更改选项卡的内容,但这些都不起作用:

tab1.html = 'new html'; // no effect
tab1.title = 'new title'; // no effect
tab1.update('new text'); // error: tab1.update is not a function
viewport.doLayout(); // no effect

Since I want to load the contents of each of the tabs via AJAX , I don't want to add tabs dynamically as suggested in this question but want the tabs to be visible from the first load and each tab's content to be changed dynamically when clicked. 由于我想通过AJAX 加载每个选项卡的内容,我不想按照此问题中的建议动态添加选项卡但希望从第一个加载中看到选项卡,并且在单击时动态更改每个选项卡的内容。

How can I change the content of a tab after it has been created? 如何在创建选项卡后更改选项卡的内容?

Update: 更新:

Thanks @Chau for catching my oversight: when I create the tabs with Ext.Panel instead of simple javascript object literals, then it works: 感谢@Chau抓住我的疏忽:当我用Ext.Panel而不是简单的javascript对象文字创建标签时,它可以工作:

var tab1 = new Ext.Panel ({
    id: 'section1',
    title: 'First Section',
    padding: 10,
    html: '(this content will be replaced with an ajax load)'
});

var tab2 = new Ext.Panel ({
    id: 'section2',
    title: 'Second Section',
    padding: 10,
    html: '(this content will be replaced with an ajax load)'
});

var tab3 = new Ext.Panel ({
    id: 'section3',
    title: 'Third Section',
    padding: 10,
    html: '(this content will be replaced with an ajax load)'
});

var modules_info_panel = new Ext.TabPanel({
    region: 'center',
    activeTab: 0,
    border: false,
    defaults:{autoScroll:true},
    items:[tab1, tab2, tab3]
});

tab1.update('new content with update'); //works

When you create tab1 it is an object with 4 properties. 创建tab1它是一个具有4个属性的对象。 When you add tab1 as an item to your tab panel, the tab panels initializer will create a tab based on the properties from tab1 . tab1作为添加到选项卡面板时,选项卡面板初始化程序将根据tab1的属性创建选项卡。 Your tab1 is still however an object with 4 properties and not a reference to the tab created by your tab panel. 但是, tab1仍然是一个具有4个属性的对象,而不是对选项卡面板创建的选项卡的引用。

I would create a panel with your 4 properties and add that panel as a child in the tab panel. 我将创建一个包含4个属性的panel ,并在选项卡面板中将该面板添加为子项。

var tab1 = new Ext.Panel({
    id: 'section1',
    title: 'First Section',
    padding: 10,
    html: '(this content will be replaced with an ajax load)'
});

Then the tab panel should use your panel instead of creating its own panel. 然后选项卡面板应使用您的面板而不是创建自己的面板。

I haven't tested this code, but I hope it will help you :) 我没有测试过这段代码,但我希望它会对你有所帮助:)

modules_info_panel.get(0) will return first tab object (by default Ext.Panel instance) so: modules_info_panel.get(0)将返回第一个tab对象(默认为Ext.Panel实例),因此:

 modules_info_panel.get(0).setTitle('new title');

will set new title 将设置新标题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM