Sencha Touch - Setting properties for a group of items
I have a simple fieldset with several fields, many of which will share some properties. I could perhaps define some extension of the Sencha Touch textfield class, but I imagine that's overkill. What's an easy way to set the common properties?
For example, I could repeat all common properties in each item, but that becomes unnecessarily large...
xtype: 'fieldset',
id: 'fieldset',
title: 'My Form Title',
items: [
{
xtype: 'textfield',
required: true,
labelAlign: 'left',
height: '50',
ui: 'customUI',
id: 'email',
name: 'email',
label: 'Email'
开发者_如何学运维 },
{
xtype: 'textfield',
required: true,
labelAlign: 'left',
height: '50',
ui: 'customUI',
inputType: 'password',
id: 'password',
name : 'password',
label: 'Password'
}
// More fields
]
A simple way would be to just use defaults
. They'll be applied to the object's items unless overridden. So, with your code, it would look something like this:
xtype: 'fieldset',
id: 'fieldset',
title: 'My Form Title',
// Place your default properties here
defaults:
{
xtype: 'textfield',
required: true,
labelAlign: 'left',
height: '50',
ui: 'customUI',
},
items: [
{
id: 'email',
name: 'email',
label: 'Email'
},
{
inputType: 'password',
id: 'password',
name : 'password',
label: 'Password'
}
// More fields
]
精彩评论