Ext JS 4 - 使用 hbox、vbox 等在表单中布局字段
我在窗口中有一个简单的 Ext JS 4 表单(MVC 样式应用程序)。下面的示例显示了 4 个字段。这个例子被简化了,但现在我需要获取这些字段并使用 hbox 和 vbox(可能还有其他?)来布局它们,
例如,我如何获取前两个字段并将其放在表单顶部的 hbox 中所以它们水平显示在表单的顶部,然后将其余字段放入该水平框下方的垂直框中,以便它们垂直显示?
(我的实际表单有更多字段,我还会有各种其他 hbox/vbox,但我只是想开始):
Ext.define('ESDB.view.encounter.Edit', {
extend: 'Ext.window.Window',
alias : 'widget.encounteredit',
title : 'Edit Encounter',
layout: 'fit',
width: 700,
autoShow: true,
initComponent: function() {
this.items = [
{
xtype: 'form',
items: [
{
xtype: 'displayfield',
name: 'id',
fieldLabel: 'ID'
},
{
xtype: 'displayfield',
name: 'cid',
fieldLabel: 'cid#'
},
{
xtype: 'displayfield',
name: 'addedDate',
fieldLabel: 'Added'
},
{
xtype: 'displayfield',
name: 'clientID',
fieldLabel: 'Client#'
}
}
]
}
我已经查看了布局的各种示例 sencha 页面 , sencha 文档,最后 另一个 - 最后一个看起来很接近 - 在表单树中,两列中的字段集,它显示了一个带有 items[] 的表单里面有一些布局代码,并且我能够让它部分工作,但无法将其转换为 hbox/vbox 样式布局。当我将其设置为 hbox 时,hbox 没有高度,因此我看不到字段。
I have a simple Ext JS 4 form inside a window (MVC style app). The example below shows 4 fields. This example is simplified, but now I need to take these fields and lay them out using hbox and vbox (and possibly others?)
How would I for example, take the first two fields and put the in a hbox at the top of the form so they display horizontally, at the top of the form, then take the rest of the fields and put them in a vbox below that hbox so they display vertically?
(my actual form has a lot more fields and I will have various other hbox/vboxes, but I am just looking to get started):
Ext.define('ESDB.view.encounter.Edit', {
extend: 'Ext.window.Window',
alias : 'widget.encounteredit',
title : 'Edit Encounter',
layout: 'fit',
width: 700,
autoShow: true,
initComponent: function() {
this.items = [
{
xtype: 'form',
items: [
{
xtype: 'displayfield',
name: 'id',
fieldLabel: 'ID'
},
{
xtype: 'displayfield',
name: 'cid',
fieldLabel: 'cid#'
},
{
xtype: 'displayfield',
name: 'addedDate',
fieldLabel: 'Added'
},
{
xtype: 'displayfield',
name: 'clientID',
fieldLabel: 'Client#'
}
}
]
}
I have looked at various examples of layout sencha page , sencha docs, and finally another one -- this last one has something that looks close - in the form tree, fieldsets in 2 columns, it shows a form with items[] and inside there some layout code, and I was able to get that to partially work, but was not able to convert it to an hbox/vbox style layout. When I set it to hbox, there is no height to the hbox, so I can not see the fields.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
举例如下:
如果您想以从上到下的形式显示块,则无需更改布局。我仅将 2 个第一个显示字段包装到具有 hbox 布局的面板中(因为您只想拆分第一行)。
Here is example:
If you want to displays blocks in form from up to down, you don't need to change layout. I've wrapped only 2 first display fields into panel with hbox layout (because you want to split only first row).
您不能在一个面板中混合两种布局。因此,您必须使用子面板根据各种规则来布局字段。这些子面板不需要(也不应该)是表单面板,只是具有表单布局的普通面板(因此您将获得字段标签)。
我经常做一些类似的事情来实现表单字段的列式布局(extjs 不太支持):所以顶部表单面板有一个 vbox 布局,然后有一些带有 hbox 布局和子面板的子面板具有包含字段的表单布局的子面板(或字段集)。在某些情况下,列布局也可能有所帮助。
PS您提到的最后一个示例(带有字段集的2列)实际上是一个带有列布局的表单面板,其中包含两个带有表单布局的字段集(子面板)。所以它的结构与我上面描述的类似。
You can't mix two layouts in a single panel. So, you have to use sub-panels to lay-out the fields according to various rules. These sub-panels don't need (and shouldn't) be form panels, just normal panels with form layout (so you will get field labels).
I routinely did something similar to achieve column-like layout for the form fields (which isn't very well supported by extjs): so the top form panel had a vbox layout, then there were some sub-panels with hbox layout and sub-sub-panels (or fieldsets) with form layout that contained the fields. Column layout could also be helpful in some cases.
PS the last example you mention (2 columns with fieldsets) is actually a form panel with column layout containing two fieldsets (subpanels) with form layout. So it's structured similar to what I've described above.