ExtJS4 - 扩展 Ext.tab.Panel 以防止设置高度值

发布于 2024-12-18 13:58:19 字数 550 浏览 4 评论 0原文

我正在将应用程序从 ExtJS 3.x 迁移到 v4,并且由于“autoHeight”属性已被删除,所以 TabPanel 遇到了一些问题。我知道,如果您没有明确定义面板的高度,则假定它是“自动高度”,但这仅在一定程度上是正确的。

在 ExtJS4 中,未设置高度的选项卡面板仍将在选项卡面板的包含 div 上设置内联 css 高度值,并且这些高度是根据每个选项卡项内容的初始高度计算的。是的,如果您更新选项卡项目的任何子组件的高度,选项卡的高度将被重新计算以适应它,或者如果选项卡包含原始 HTML 并且选项卡的 update() 方法用于更改该内容,其高度将再次调整以适合。

无论如何,在我的应用程序中,问题在于我使用 ExtJS 框架中的方法以外的方法(例如 jQuery.html())更新这些选项卡的原始 HTML 内容。由于选项卡面板没有收到有关内容更改的通知,因此它不会重新计算选项卡的高度值。

为了解决这个问题,我要做的就是确保选项卡面板的包含元素在渲染、重新渲染或其他任何操作时始终设置为 height:auto。我假设要完成此任务,我需要扩展 TabPanel,但我不知道从哪里开始以及要覆盖哪些方法等。有什么想法吗?

I am migrating an application from ExtJS 3.x to v4 and have been having some troubles with the TabPanel's now that the "autoHeight" property has been removed. I know that if you do not explicitly define a height for the panel it is assumed to be "auto height", but that is only true to a degree.

In ExtJS4, a tab panel with no height set will still have inline css height values set on the tab panel's containing divs, and those heights are calculated from the initial height of each tab item's content. And yes, if you update the height of any child components of the tab items, the height of the tab will be recalculated to fit it, or if the tab contains raw HTML and the tab's update() method is used to change that content, its height again, will be adjusted to fit.

Where the issue is, in my application anyway, is that I update the raw HTML content of those tab's using methods other than those in ExtJS's framework, such as jQuery.html(). Since the tab panel is not being notified of this change to the content, it does not recalculate the height value of the tab.

To get around this all I want to do is ensure that the tab panel's containing elements always are set to height:auto when rendered, re-rendered, or anything else. I'm assuming to accomplish this I would need to extend the TabPanel, but i don not know where to start as far as what methods to override, ect. Any thoughts?

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

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

发布评论

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

评论(2

月棠 2024-12-25 13:58:20

这就是我最终所做的。这绝对不理想,相当老套,但似乎工作正常。也许有人会更好地了解我现在正在尝试完成的任务,并且可以提出更好的实现:-)

Ext.define('Ext.tab.AutoHeightPanel', {
    extend: 'Ext.tab.Panel',
    alias: 'widget.autoheighttabs',

    constructor: function(cnfg){
        this.callParent(arguments);
        this.initConfig(cnfg);
        this.on('afterlayout', this.forceAutoHeight, this);
        this.on('afterrender', this.forceAutoHeight, this);
        this.on('resize', this.forceAutoHeight, this);
    },

    forceAutoHeight: function(){
        this.getEl().applyStyles({height : 'auto', overflow : 'visible'});
        this.items.each(function(item, idx, len) {
            if(Ext.isDefined(item.getEl())) item.getEl().applyStyles({height : 'auto', overflow : 'visible'});
        });
    }
});  

您可能想在您的 style 配置中添加一个“margin-bottom”值选项卡面板,以防止内容抵住面板底部。

This is what I ended up doing. It's definitely not ideal, pretty hacky but it seems to work ok. Maybe someone will better see what I'm try to accomplish now, and can come up with a better implementation :-)

Ext.define('Ext.tab.AutoHeightPanel', {
    extend: 'Ext.tab.Panel',
    alias: 'widget.autoheighttabs',

    constructor: function(cnfg){
        this.callParent(arguments);
        this.initConfig(cnfg);
        this.on('afterlayout', this.forceAutoHeight, this);
        this.on('afterrender', this.forceAutoHeight, this);
        this.on('resize', this.forceAutoHeight, this);
    },

    forceAutoHeight: function(){
        this.getEl().applyStyles({height : 'auto', overflow : 'visible'});
        this.items.each(function(item, idx, len) {
            if(Ext.isDefined(item.getEl())) item.getEl().applyStyles({height : 'auto', overflow : 'visible'});
        });
    }
});  

You may want to add a 'margin-bottom' value to the style config of your tab panel to prevent content from butting up against the bottom of the panel.

但可醉心 2024-12-25 13:58:20

吸引人的部分是让 ExtJS 知道组件已更新。基本上,您需要重新计算组件布局。您可以使用Panel 类提供的方法doLayout( )。通过调用此方法,您将强制要求重新计算和刷新布局。我想这应该对你有帮助。

The catchy part is making ExtJS aware that the component is updated. You need to basically, recalculate the component layout. You can use the method doLayout( ) available with the Panel class. By calling this, you are forcefully asking to the layout to be recalculated and refreshed. I think this should help you out.

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