Extjs:如何定义自定义菜单的工作布局
ExtJS: 我有一个按钮,我想在其中关联菜单。我想自己定义菜单的布局,并根据我从 文档,可以直接指定布局。
按钮 + 菜单:
{
xtype: 'button',
menu: {
xtype: 'menu',
plain: true,
layout: 'fit',
height: 300,
width: 200,
items:
[
{
xtype: 'container',
layout: 'vbox',
layoutConfig: {
align: 'stretch',
pack: 'start'
},
items:
[
{
xtype: 'label',
text: 'Label1'
}, {
xtype: 'label',
text: 'Label2'
}, {
xtype: 'textfield'
}
]
}
]
},
menuAlign: 'bl-tl',
text: 'Button'
}
结果高度为零,但是如果我将 xtype: 'menu'
更改为 xtype: 'panel'
并将其放置在 Ext.Window
内,然后它就像我想要的那样工作。
问题:我应该如何自定义菜单才能以正确的高度获得我想要的内容?
ExtJS:
I have a button where I want to associate a menu. I want to define the layout of the menu myself, and from what I gather from the documentation, the layout can be specified directly.
Button + menu:
{
xtype: 'button',
menu: {
xtype: 'menu',
plain: true,
layout: 'fit',
height: 300,
width: 200,
items:
[
{
xtype: 'container',
layout: 'vbox',
layoutConfig: {
align: 'stretch',
pack: 'start'
},
items:
[
{
xtype: 'label',
text: 'Label1'
}, {
xtype: 'label',
text: 'Label2'
}, {
xtype: 'textfield'
}
]
}
]
},
menuAlign: 'bl-tl',
text: 'Button'
}
The result has zero height, but If I change the xtype: 'menu'
to xtype: 'panel'
and put it inside an Ext.Window
, then it works like I want it too.
Question: How should I customize the menu to get what I want with the correct height?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 Sencha 论坛上问了同样的问题并得到了以下帮助:
对我来说,关键点是不要在菜单上设置任何布局或大小属性,而是在嵌套容器上设置。
forceLayout: true
属性可能也对我有帮助:)I asked the same question at the Sencha forums and got the following help:
The key points for me was to not set any layout or size attributes on the menu, but instead do it on the nested container. The
forceLayout: true
attribute might also have helped me :)简单的解决方案,使用您的答案和论坛帖子,在我的例子中,我将菜单传递到按钮中。这是我在 Ext 4.0.2 中基于上述内容想出来的。只是想我会发帖以防万一以后有人来访问,或者万一煎茶论坛瘫痪了。
首先,我为菜单项指定一个锚点和一个高度。请注意,home_menu 只是一个常规数组。
然后,菜单本身的重要配置是 forceLayout 和 autoHeight:
Simple solution, using the your answer and the forum post, in my case I am passing a menu into a button. This is what I came up with in Ext 4.0.2 based on the above. Just thought I would post in case anyone comes to visit later, or in case the sencha forums are ever down.
First, I give the menu items an anchor and a height. Note that home_menu is simply a regular array.
Then, the important configs for the menu itself are forceLayout and autoHeight: