2013-09-21 54 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