如何更新 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]
});
然后在创建此选项卡面板后,我想动态更改选项卡的内容,但这些都不起作用:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您创建
tab1
时,它是一个具有 4 个属性的对象。当您将tab1
作为 item 添加到选项卡面板时,选项卡面板初始化程序将根据tab1
的属性创建一个选项卡。然而,您的tab1
仍然是一个具有 4 个属性的对象,而不是对选项卡面板创建的选项卡的引用。我将使用您的 4 个属性创建一个
panel
并将该面板添加为选项卡面板中的子面板。然后选项卡面板应该使用您的面板而不是创建自己的面板。
我还没有测试过这段代码,但我希望它能帮助你:)
When you create
tab1
it is an object with 4 properties. When you addtab1
as an item to your tab panel, the tab panels initializer will create a tab based on the properties fromtab1
. Yourtab1
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.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)
将返回第一个选项卡对象(默认为 Ext.Panel 实例),因此:将设置新标题
modules_info_panel.get(0)
will return first tab object (by default Ext.Panel instance) so:will set new title