javascript - 从 JSON 到 Servlet 数据

标签 javascript json jsp servlets extjs4

我开始为我的 ExtJS 支持的 UI 学习 JSON,但现在我遇到了如何将数据从 servlet 传递到 JSP 组合框的问题。

我的 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();

希望我做得对。 :) 请帮忙。

最佳答案

Ext.data.SimpleStore 定义应定义“fields”属性。

例如,

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 
});

关于javascript - 从 JSON 到 Servlet 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15350549/

相关文章:

json - Golang 将 JSON 解码为一个字符串和一个 float64 的 slice

javascript - 如何使用 jQuery 设置 div 样式?

javascript - Meteor:process.env.MAIL_URL 敏感信息

javascript - ExtJS 包括 Ex.ux.ComboColumn

ruby-on-rails - 事件记录分组并与 json 数据求和

javascript - 如何将 json 对象字符串传递给 javascript 函数?

java - JSF 运行时异常 : Cannot find FacesContext

jsp - 什么是 Web 应用程序中的 .jspa URL 扩展名?

javascript - 如何在 JavaScript 中检查 DOM 节点的文本溢出属性

javascript - 正则表达式仅允许数字右侧带有字母。前 (1d 4h 32m)