在组合框MultiSelect extjs上加载数据

klsxnrf1  于 2022-11-04  发布在  其他
关注(0)|答案(1)|浏览(151)

我有一个组合框与多选设置为我的水果项目。
因此,在创建用户饮食习惯表期间,用户能够选择多个水果选项,当我编辑用户饮食习惯时,我的问题出现了,该表无法显示现有的水果选项。
“在水果处显示”组合框创建新用户表单-已吃水果:苹果、橙子
加载上一个用户时,结果应与上述相同,但仅显示为空
组合框中的部分代码如下所示

{
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将结果名称显示到组合框中

{
  "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所说的那样,组合框能够将fruitseaten显示为show,但对玛丽来说,组合框值为空,选择也为空

jv4diomz

jv4diomz1#

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

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

相关问题