繁体   English   中英

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

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

我有一个这样的标签面板:

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]
});

然后在创建此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

由于我想通过AJAX 加载每个选项卡的内容,我不想按照此问题中的建议动态添加选项卡但希望从第一个加载中看到选项卡,并且在单击时动态更改每个选项卡的内容。

如何在创建选项卡后更改选项卡的内容?

更新:

感谢@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

创建tab1它是一个具有4个属性的对象。 tab1作为添加到选项卡面板时,选项卡面板初始化程序将根据tab1的属性创建选项卡。 但是, tab1仍然是一个具有4个属性的对象,而不是对选项卡面板创建的选项卡的引用。

我将创建一个包含4个属性的panel ,并在选项卡面板中将该面板添加为子项。

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

然后选项卡面板应使用您的面板而不是创建自己的面板。

我没有测试过这段代码,但我希望它会对你有所帮助:)

modules_info_panel.get(0)将返回第一个tab对象(默认为Ext.Panel实例),因此:

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

将设置新标题

暂无
暂无

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

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