【问题标题】:How can I update the content of a tab in an ExtJS TabPanel?如何更新 ExtJS TabPanel 中选项卡的内容?
【发布时间】:2010-12-20 10:03:10
【问题描述】:

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

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 加载每个选项卡的内容,我不想动态添加选项卡as suggested in this question 但希望选项卡是在第一次加载时可见,并且每个标签的内容在点击时会动态更改

标签创建后如何更改其内容?

更新:

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

【问题讨论】:

    标签: javascript extjs tabpanel


    【解决方案1】:

    当您创建 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)'
    });
    

    那么标签面板应该使用你的面板而不是创建自己的面板。

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

    【讨论】:

      【解决方案2】:

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

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

      将设置新标题

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多