2013-03-11 70 views
1

我開始學習JSON我的ExtJS的供電UI,但現在我有關於如何從我的servlet到JSP組合框傳遞數據的問題..從JSON到Servlet的數據

我的servlet的輸出已經確定。 (我希望如此。:))這是我的servlet代碼..

JSONArray jsonarray = new JSONArray(); 
      ResultSetMetaData rsmd = rs.getMetaData(); 

      int y = 1; 
      while(rs.next()){ 
       int numColumns = rsmd.getColumnCount(); 
       JSONObject obj = new JSONObject(); 

      for (int i=1; i<numColumns+1; i++) { 
       String column_name = rsmd.getColumnName(1); 
        String column_value = rs.getString(i); 
        obj.put(column_value, y); 

       } 

       jsonarray.put(obj); 

       y++; 
      } 

然後我在ExtJS中的組合框是;

  xtype: 'combo', 
    name: 'genre', 
    fieldLabel: 'Genre', 
    mode: 'local', 
    store: genres2, 
    width: 120,    
    forceSelection: true, 
    typeAhead: true, 
    triggerAction: 'all', 
    emptyText:'Select materials...', 
    selectOnFocus:true, 
    displayField: 'column_value' 

var genres2 = new Ext.data.SimpleStore({ 
    root: 'rows', 
    totalProperty: 'totalCount', 
    method: 'POST', 
    proxy: new Ext.data.HttpProxy({ 
     url : '/ExtJS_Sample/ConnectionServlet' 
    }), 

    autoLoad: true 
}); 

genres2.load(); 

希望我這樣做是正確的。 :) 請幫忙。

回答

0

Ext.data.SimpleStore定義應該有'字段'屬性定義。

例如,

Ext.data.SimpleStore({ 
root: 'rows', 
fields: [ {name: 'company'}, 
      {name: 'price', type: 'float'}, 
      {name: 'change', type: 'float'}, 
      {name: 'pctChange', type: 'float'}], 
totalProperty: 'totalCount', 
method: 'POST', 
proxy: new Ext.data.HttpProxy({ 
      url : '/ExtJS_Sample/ConnectionServlet' 
     }), 
autoLoad: true 
});