如何从数组中设置 Sencha Touch 中的选择字段?

How to set a selectfield in Sencha Touch from array?

我在 Sencha Touch 应用程序中工作,我想推入一个组合框,之前从商店过滤的值。

var store = Ext.getStore('Surveys');
var templatesAvailable = [];
store.filterBy(function (record) {
  console.log(record.get('templateName'));
  record.get('templateName'); --> I get value
  templatesAvailable.push(record.get('templateName')); --> into the array
});

下一步是将数组传输到指定的选择器,例如在我的例子中...

this.getTemplateSelector

  {
    xtype       : 'selectfield',
    itemId      : 'selectSurveysTemplates',
    cls         : 'filterbar-selectfieldplus',
    displayField: 'value',  --> here is the secret  ;-)
    valueField  : 'id',
    autoCreate  : true
  },

这个实现的正确方法应该是什么?我已经用不同的选项进行了测试,但它对我不起作用..

提前谢谢你..

这个怎么样:

selectfield.setOptions(
    store.getRange().map(function(record) {
        return {
            text:record.get("templateName"),
            value:record.get("templateName")
        };
    })
);

这应该执行以下操作:

瞧,你应该完成了。