【发布时间】:2013-07-13 01:38:37
【问题描述】:
我正在尝试使用子元素创建自定义组件是否是一种好方法。在我的大多数表单中,我都会有一些字段水平对齐,大小相同。
我的第一个想法是创建一个自定义 FieldContainer 并且已经声明了我现在将存在的项目,但我不想在这个扩展类中设置他的名字和 ID。我想让最终类负责,也许还有子项的更多属性。
那么,是否可以在将使用我的自定义组件的类中定义 config 的子项?
示例
Ext.define('MyApp.view.LookupContainer', {
extend: 'Ext.form.FieldContainer',
layout: {
type: 'column'
},
labelAlign: 'right',
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'numberfield',
columnWidth: 0.15,
width: 70,
labelWidth: 0,
maxValue: 99999,
minValue: 0
},
{
xtype: 'textfield',
columnWidth: 0.75,
margin: '0 0 0 5',
readOnly: true
},
{
xtype: 'button',
cls: 'x-formButton',
margin: '0 0 0 5',
overCls: 'x-formButtonOver',
iconCls: 'icon-lov'
},
{
xtype: 'button',
margin: '0 0 0 5',
iconCls: 'icon-program'
}
]
});
me.callParent(arguments);
}
});
Ext.onReady(function() {
var container = Ext.create('MyApp.view.LookupContainer');
//how to set the items properties here?
});
【问题讨论】:
-
你会为
MyApp.view.LookupContainer添加更多行为吗?或者您只是想将它用作您问题中的简单容器? -
我认为物品会比容器有更多的行为。这个容器的责任更多地在于展示(图标、边距和大小)。