如何从阵列中设置Sencha Touch中的选择字段

How to set a selectfield in Sencha Touch from array?

本文关键字:Touch 选择 字段 Sencha 设置 阵列      更新时间:2023-09-26

我在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")
        };
    })
);

这应该执行以下操作:

  • CCD_ 2设置CCD_ 3的值。根据文档,options采用属性为textvalue的对象数组,所以我猜setOptions也采用相同的属性
  • Store.getRange为您提供了一组记录
  • CCD_ 9,它采用一个函数并使用该函数转换输入数组中的每个项

瞧,你应该完了。