selectField与sencha touch中的商店

时间:2013-09-10 13:46:36

标签: sencha-touch-2

我的selectfield结构如下:

{
  xtype: 'selectfield',
  label: 'Name :',
  name: 'description',
  displayField: 'description',
  valueField: '_description',
  store: 'ABC',
  autoSelect: true,
  labelWidth:'35%',
  readOnly:true
}

如何将默认值设置为--select-- 这可能吗。 请提前指导我或提供工作代码。

2 个答案:

答案 0 :(得分:0)

我认为你正在寻找placeholder

{
    xtype: 'selectfield',
    placeholder: '--select--',
    ...
}

请参阅此处的文档:http://docs.sencha.com/touch/2.2.1/#!/api/Ext.field.Input-cfg-placeHolder

答案 1 :(得分:0)

如果您想在字段中设置实际值,即您要求的“默认值”,您可以在模型上设置默认值,例如

Ext.define('Core.model.MyModel', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            { name: 'description', type: 'string', defaultValue: '--select--' }
        ]
    }
});

然后在您的商店'ABC'上确保模型设置正确,即model: 'Core.model.MyModel

如果您只是想要一个占位符标签显示'--select--' - 纯粹出于装饰/审美目的,而不是当时会使用的实际值,那么kevhender的答案是正确的,即{{1} } property。