「已注销」 2010-06-24 11:49
浏览 302
已采纳

Ext ComboBox 从Servlet 加载不出来数据

[code="servlet"]public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

    response.setContentType("text/html;charset=gbk");
    PrintWriter out = response.getWriter();     
    String json="[{cid:1,cname:'武汉市'},{cid:2,cname:'荆门市'},{cid:3,cname:'宜昌市'},{cid:4,cname:'沙洋市'},{cid:5,cname:'潜江市'}]";
    out.println(json);
    out.flush();
    out.close();
}[/code]

[code="js"]
Ext.onReady(function() {

        var proxy = new Ext.data.HttpProxy({
                    url : "CityJsonServlet"
                });

        var City = Ext.data.Record.create([{
                    name : "cid",
                    type : "int",
                    mapping : "cid"
                }, {
                    name : "cname",
                    type : "string",
                    mapping : "cname"
                }]);
        var reader = new Ext.data.JsonReader({}, City);

        var store = new Ext.data.Store({
                    proxy : proxy,
                    reader : reader,
                    autoLoad:true
                });

        var combobox = new Ext.form.ComboBox({
                    triggerAction : "All",
                    store : store,
                    displayField : "cname",
                    valueField : "cid",
                    mode : "remote",
                    emptyText : "请选择市",
                    renderTo : Ext.getBody()
                })

    })

[/code]
[code="jsp"]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Dnamic ComboBox Example
href="./scripts/ext/resources/css/ext-all.css" />
src="./scripts/ext/adapter/ext/ext-base.js">

<br><br>



[/code]

  • 写回答

3条回答 默认 最新

  • zhoujuan520 2010-06-24 13:31
    关注

    [code="java"]public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

        response.setContentType("text/html;charset=gbk");
        PrintWriter out = response.getWriter();     
        String json="[{cid:1,cname:'武汉市'},{cid:2,cname:'荆门市'},{cid:3,cname:'宜昌市'},{cid:4,cname:'沙洋市'},{cid:5,cname:'潜江市'}]";
    
                out.write(json);//out.println(json);
    
                out.flush();
        out.close();
    }[/code]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器