在 ComboBox MultiSelect extjs 上加载数据

Load Data on ComboBox MultiSelect extjs

我的水果项目有一个带有多个select设置的组合框。

所以在创建用户饮食习惯表格时,用户可以select多种水果selection,我的问题出现在我编辑用户饮食习惯时,表格无法显示现有水果select离子.

显示在水果组合框 创建新的用户表单 - Fruits Eaten: Apple,Orange
当加载以前的用户时应该与上面的结果相同但它只是显示空

组合框中的部分代码是这样的

 {
xtype:'combobox',
fields: 'Fruits Eaten:',
editable: false,
displayField'name',
store:'FruitStore',
valueField:'name',
multiSelect:true
    }

商店模型代码是这样的

 Ext.define('FruitModel',{
     extend: 'Ext.data.Model',
    requires:[
    'Ext.data.field.Field'
    ],
    fields:[
    {
    mapping:'_source.name',
    name:'name'
    },
    {
    mapping:'_source.code',
    name:'code'
    }
    ]
    });

水果的结果通过elasticsearch将名称显示到combobox

{
  "took":3,
  "timed_out":false,
  "_shards":
  {
    "total":1,
    "successful":1,
    "skipped":0,
    "failed":0
  },
  "hits":{
    "total":{
      "value":4,
      "relation":"eq"
    },
    "max_score":1.0,
    "hits":[
      {
        "_index":"fruits",
        "_type":"_doc",
        "_id":1,
        "_score":1.0,
        "_source":{
          "name":"Apple",
          "code":"AP"
        }
      },
      {
        "_index":"fruits",
        "_type":"_doc",
        "_id":2,
        "_score":1.0,
        "_source":{
          "name":"Orange",
          "code":"OR"
        }
      },
      {
        "_index":"fruits",
        "_type":"_doc",
        "_id":3,
        "_score":1.0,
        "_source":{
         "name":"Blueberry",
          "code":"BB"
        }
      },
      {
        "_index":"fruits",
        "_type":"_doc",
        "_id":4,
        "_score":1.0,
        "_source":{
          "name":"Pear",
          "code":"PE"
        }
      }
      ]
  }
}

用户表单结果如下

{
  "took":3,
  "timed_out":false,
  "_shards":
  {
    "total":1,
    "successful":1,
    "skipped":0,
    "failed":0
  },
  "hits":{
    "total":{
      "value":4,
      "relation":"eq"
    },
    "max_score":1.0,
    "hits":[
      {
        "_index":"students",
        "_type":"_doc",
        "_id":1,
        "_score":1.0,
        "_source":{
          "name":"John",
          "fruitseaten":"Apple"
        }
      },
      {
        "_index":"students",
        "_type":"_doc",
        "_id":2,
        "_score":1.0,
        "_source":{
          "name":"Mary",
          "fruitseaten":"Apple,Orange"
        }
      },
      {
        "_index":"students",
        "_type":"_doc",
        "_id":3,
        "_score":1.0,
        "_source":{
         "name":"Karen",
          "fruitseaten":"Blueberry"
        }
      },
      {
        "_index":"students",
        "_type":"_doc",
        "_id":4,
        "_score":1.0,
        "_source":{
          "name":"Sam",
          "fruitseaten":"Pear"
        }
      }
      ]
  }
}

就像我之前对 Sam、Karen 和 John 所说的那样,组合框能够将 fruiteaten 显示为 show 但对于 Mary,组合框值是空的,selection 也是空的

尝试将从后端返回的字符串值转换为数组。在 students 的模型定义中,在定义 fruitseaten 字段的位置添加一个 convert 函数:

fields: [
    {
        mapping: '_source.fruitseaten',
        name: 'fruitseaten',
        convert: function(v, record) {
            return v.split(',');
        }
    },
]