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

标签 javascript sencha-touch

我有一个包含多个字段的简单字段集,其中许多字段将共享一些属性。我也许可以定义 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/

相关文章:

javascript - 在 Sencha Touch 中按需加载 NestedList 的项目

sencha-touch - 如何将自定义按钮添加到 navigation.View (Sencha Touch 2) 单个页面上的标题栏?

jquery - 有没有更好的Android webview

html - 移动网络应用程序的服务器端架构

javascript - jquery中双击时如何停止拖动事件

javascript - AWS 开发工具包 getOjbect 不返回文件

javascript - ng-repeat 在 Angular.js 中生成额外的 td

javascript - 使用 jQuery 移动翻转开关更改文本颜色

javascript - 指示器在 loadmask sencha touch 中不起作用

javascript - 如何检测设备是否支持鼠标?