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

发布于 2024-10-08 14:29:16 字数 2040 浏览 6 评论 0原文

我有一个像这样的选项卡面板:

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

然后在创建此选项卡面板后,我想动态更改选项卡的内容,但这些都不起作用:

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< 加载每个选项卡的内容/strong>,我不想动态添加选项卡按照这个问题中的建议,但希望选项卡从第一次加载时可见,并且每个选项卡的内容动态更改当点击时。

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

更新:

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

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:

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.

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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往日 2024-10-15 14:29:16

当您创建 tab1 时,它是一个具有 4 个属性的对象。当您将 tab1 作为 item 添加到选项卡面板时,选项卡面板初始化程序将根据 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)'
});

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

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

When you create tab1 it is an object with 4 properties. 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. Your tab1 is still however an object with 4 properties and not a reference to the tab created by your tab panel.

I would create a panel with your 4 properties and add that panel as a child in the tab 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 :)

夜访吸血鬼 2024-10-15 14:29:16

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

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

将设置新标题

modules_info_panel.get(0) will return first tab object (by default Ext.Panel instance) so:

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

will set new title

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文