2012-07-24 44 views
1

鑑於以下的javascript:EXTJS COMBOX - 商店做負載,但並沒有顯示

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"} ]} 

回答

0

你必須根設置爲您所使用的JSON讀者,默認爲「」,你的應該是:

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

您也可以考慮用模型對象(來自docs)字段來替換字段配置:通常應避免使用此配置選項,它存在用於向後兼容的目的

+0

Thanx,解決方案和學習點,切換到模型! – Paul 2012-07-24 12:09:34

0

更改組合框模式,從本地到遠程mode: 'remote'和使用JSON店:

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

在你的店,你錯過了root屬性

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配置並使用遠程查詢獲得更好的性能