Sencha Touch - 设置一组项目的属性

时间:2011-09-02 16:31:03

标签: javascript sencha-touch

我有一个包含多个字段的简单字段集,其中许多字段将共享一些属性。我或许可以定义Sencha Touch文本字段类的一些扩展,但我想这太过分了。设置公共属性的简单方法是什么?

例如,我可以重复每个项目中的所有常见属性,但这会变得不必要地大...

        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
        ]

1 个答案:

答案 0 :(得分:0)

一种简单的方法就是使用defaults。除非被覆盖,否则它们将应用于对象的项目。因此,使用您的代码,它看起来像这样:

    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
    ]
相关问题