2013-09-21 60 views
2

我正在使用Extjs 4.1,試圖爲Combobox加載數據,但不起作用。我對hte json reader root/record有強烈的懷疑。Extjs 4 Combobox數據存儲不能顯示數據

數據模型和存儲的定義,

Ext.define('tagModel', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     {name: 'id', type: 'string'}, 
     {name: 'name', type: 'string'} 
    ] 
}); 

var tagStore = new Ext.data.Store({ 
    model: 'tagModel', 
    proxy: { 
     type: 'ajax', 
     url: '/ExtjsWebApp/webresources/question/loadTags', 
     reader: { 
      type: 'json',    
      record : 'rtnList' 
     }  
    }, 
    listeners: {  
     load: function(store, records, options){ 
      alert("success " +records.length); 
     }    
    }, 
    autoLoad: true 
}); 

組合框的定義是這個,

{ 
      itemId: 'search_tag_fld', 
      fieldLabel: 'Tag', 
      xtype: 'combobox', 
      displayField: 'name', 
      valueField: 'id', 
      store: tagStore, 
      queryMode: 'remote', 
      multiSelect: true, 
      anchor: '100%',   
      labelHeight: 300    
     } 

我敢肯定,RESTful Web服務將返回數據,因爲這

{"rtnList":[{"id":1,"name":"Java","active":"true"},{"id":2,"name":"J2EE","active":"true"},{"id":3,"name":"JMS","active":"true"},{"id":4,"name":"Design","active":"true"},{"id":5,"name":"SOA","active":"true"}],"successMsg":"success","errorMsg":"","time":"09/21/2013 18:34:55","sessionId":null,"userId":null} 

回答

0

在您的閱讀器中,將「記錄」更改爲「root」。這裏有一個小提示,表明您當前的設置將工作得很好:https://fiddle.sencha.com/#fiddle/km

+0

謝謝。那麼如何檢索'successMsg'的值? – user595234

+0

連接到商店代理的讀者將具有存儲在名爲「rawData」的配置中的完整響應。你可以像這樣訪問它:store.getProxy()。getReader()。rawData – existdissolve