【问题标题】:EXTJS Combox - Store does load but doesn't showEXTJS Combox - 商店确实加载但不显示
【发布时间】:2017-09-04 22:02:01
【问题描述】:

鉴于以下 javascript:

var fo = Ext.create('Ext.form.Panel', {
    layout:'box',
    ...
    items: [{
        xtype: 'combobox',
        valueField: 'id',
        displayField: 'organizationtype',
        store: {
            storeId: 'zaza',                
            fields: [{name: 'id'}, {name: 'organizationtype'}],
            root: 'data',
            autoLoad: true,
            proxy: {
                type: 'ajax',
                url: '/apps/crm_organizations/orgtype/',
                reader: {
                    type: 'json'
                }
            }
        },
        fieldLabel: 'Type relation',
        name: 'organizationtype',
        queryMode: 'local',
    },
            ...

此面板包含 - 除其他字段外 - 还包含此组合框。我可以通过 wireshark 看到实际上查询了 url '/apps/crm_organizations/orgtype/'。但是组合框不显示任何值。这与我懒加载组合框有关吗?

这是对 JSON 请求的响应:

{data: [ {id:"1" ,organizationtype:"Customer"} 
,{id:"2" ,organizationtype:"Relation"} 
,{id:"3" ,organizationtype:"Supplier"} 
,{id:"4" ,organizationtype:"Unknown"} ]}

【问题讨论】:

    标签: extjs extjs4


    【解决方案1】:

    您必须将根设置为您正在使用的json阅读器,默认为“”,您的应该是:

    reader: {
                        type: 'json',
                        root: 'data'
                    }
    

    您也可以考虑用模型对象替换字段配置。(来自文档)字段:通常应避免使用此配置选项,它的存在是为了向后兼容

    【讨论】:

    • 谢谢,对于解决方案和学习点,切换到模型!
    【解决方案2】:

    将组合框模式从本地更改为远程 mode: 'remote' 并使用 json 存储:

    store: {
        xtype: 'jsonstore',
        url: '/apps/crm_organizations/orgtype/',
        autoLoad: true,
        idProperty: 'id',
        root: 'data',
        fields: ['id','organizationtype'],
    },
    mode: 'remote'
    

    【讨论】:

      【解决方案3】:

      在您的商店中,您缺少根属性

      store: {
        storeId: 'zaza',       
        fields: [{name: 'id'}, {name: 'organizationtype'}],
        root: 'data',
        autoLoad: true,
        proxy: {
          type: 'ajax',
          url: '/apps/crm_organizations/orgtype/',
          reader: {
            type: 'json',
            root:'data'
          }
        }
      }
      

      如果您的组合是跨域查询信息,则使用 jsonp 配置并使用远程查询以获得更好的性能

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-06
        • 2020-04-14
        • 2011-01-15
        • 2011-12-02
        • 1970-01-01
        • 2013-03-17
        相关资源
        最近更新 更多