ExtJS:不正确的下拉菜单对齐方式

标签 extjs extjs4

我有一个带有菜单和自定义 menuAlign 设置的拆分按钮(这样下拉菜单的右上角将与拆分按钮的右下角对齐)。

问题:第一次单击拆分按钮时,菜单未正确对齐。然而,随后的点击工作正常。在 Chrome 和 FF、ExtJS 4.0.2a 中看到相同的行为。

有任何想法吗?谢谢!

enter image description here

enter image description here

{
    xtype: 'toolbar',
    items: [
        {
            xtype: 'triggerfield',
            width: 335,
            emptyText: 'Search',
            triggerCls: 'x-form-search-trigger'
        },
        '->',
        {
            xtype: 'splitbutton',
            text: 'Account',
            menuAlign: 'tr-br',
            menu: {
                xtype: 'menu',
                plain: true,
                items: [
                    {
                        xtype: 'container',
                        html: 'image here...'
                    },
                    {
                        xtype: 'button',
                        width: 10,
                        text: 'Log Out'
                    }
                ]
            }
        }
    ]
}

最佳答案

好的,所以我想出了一个“它不是很漂亮,但它完成了工作”的解决方法:快速隐藏,然后显示,渲染后的菜单。换句话说,当有人第一次点击并呈现菜单时,自动隐藏它然后再次显示它。当它重新显示时,对齐是正确的。这是新代码:

{
    xtype: 'toolbar',
    items: [
        {
            xtype: 'triggerfield',
            width: 335,
            emptyText: 'Search',
            triggerCls: 'x-form-search-trigger'
        },
        '->',
        {
            xtype: 'splitbutton',
            text: 'Account',
            menuAlign: 'tr-br',
            menu: {
                xtype: 'menu',
                plain: true,
                items: [
                    {
                        xtype: 'container',
                        html: 'Image here...'
                    },
                    {
                        xtype: 'button',
                        text: 'Log Out'
                    }
                ],
                listeners: {
                    afterrender: function(component) {
                        // Hide menu and then re-show so that alignment is correct.
                        component.hide();
                        component.show();
                    }
                }
            }
        }
    ]
}

关于ExtJS:不正确的下拉菜单对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6687551/

相关文章:

javascript - Extjs显示/隐藏的正确方法

extjs - 将图表导出为 PDF 以进行打印 EXT JS 4

javascript - Extjs 数据模型/存储是否支持任何包装代理构建器方法?

extjs - 如何使用过滤后的数据保留 ExtJS 网格中的选择?

extjs4 - Extjs 组合框自动完成

google-maps-api-3 - 在 ExtJS 4 中动态加载 Google Maps API v3

extjs - 调用事件因所有参数而延迟

extjs - 监听 View Controller 之间的事件

javascript - Extjs 中的容器与面板

css - ExtJS 4 - CSS - PropertyGrid 列标题/属性样式