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

Sencha Touch - Setting properties for a group of items

本文关键字:一组 项目 设置 属性 Touch Sencha      更新时间:2023-09-26

我有一个包含几个字段的简单字段集,其中许多字段将共享一些属性。我也许可以定义Sencha Touch textfield类的一些扩展,但我想那有点过头了。设置公共属性的简单方法是什么?

例如,我可以在每个条目中重复所有公共属性,但这会变得不必要的大…

        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
        ]

一个简单的方法就是使用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
    ]