我有一个包含多个字段的简单字段集,其中许多字段将共享一些属性。我也许可以定义 Sencha Touch 文本字段类的一些扩展,但我认为这有点过分了。设置公共(public)属性的简单方法是什么?
例如,我可以在每个项目中重复所有常见属性,但这会变得不必要的大...
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
]
最佳答案
一个简单的方法是仅使用默认值
。除非被覆盖,否则它们将应用于对象的项目。因此,对于您的代码,它看起来像这样:
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
]
关于javascript - Sencha Touch - 设置一组项目的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7286520/