ext js代码如下Ext.onReady(function() {


// 创建远程代理
var httpProxy = new Ext.data.HttpProxy({
url : "/test/groupGridController.js"
});var record = new Ext.data.Record.create([{
name : "studentid"
}, {
name : "studentname"
}, {
name : "birthday"
}, {
name : "department"
}, {
name : "professional"
}])// 创建解析方式
var jsonReader = new Ext.data.JsonReader({
totalProperty : 'results',
root : 'items'
}, record);// json分组数据源
var jsonStore = new Ext.data.Store({
reader : jsonReader,
proxy : httpProxy,
autoLoad : true
}) jsonStore.on('load', function() {
alert("数据加载完成:" + jsonStore.getCount());,这里一直没执行到,请问是什么原因
});
// 创建列解析模型
var columns = new Ext.grid.ColumnModel({
defaults : {
sortable : true
},
columns : [{
header : '编号',
dataIndex : 'studentid'
}, {
header : '姓名',
dataIndex : 'studentname'
}, {
header : '出生日期',
dataIndex : 'birthday',
type : 'date',
renderer : Ext.util.Format.dateRenderer('Y年m月d日')
}, {
header : '系部',
dataIndex : 'department'
}, {
header : '专业',
dataIndex : 'professional'
}]
});
var grid = new Ext.grid.GridPanel({
title : '表格分组一',
renderTo : "groupGrid",
autoHeight : true,
width : 600,
cm : columns,
store : jsonStore
}); 
});输出json的是jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'groupGridController.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
<%
String resultJson = "{'results':1,'items':[{'birthday':'1985-05-09','department':'机械','professional':'车工','studentid':'1','studentname':'张三'}]}";
response.setCharacterEncoding("utf-8");
out.print(resultJson); 
 System.out.println(resultJson);
%>
</body>
</html>jsp输出的json字符串如下:
{'results':1,'items':[{'birthday':'1985-05-09','department':'机械','professional':'车工','studentid':'1','studentname':'张三'}]}请问红色部分为什么没有值。
而且表格里面也加载不了数据。解决后立即给分

解决方案 »

  1.   

    jsonStore.load({  
      params: {start:0, limit:30},  
      callback: function(r, options, success){  
        if(success){  
          Ext.Msg.alert('操作','成功!');  
        }else{  
          Ext.Msg.alert('操作','失败!');  
        }  
      } 
    });
    这样来写
      

  2.   

    jsp只要输出json数据本身,不能包含<html>之类的非js代码
      

  3.   


    Ext.Ajax.request({    
    url: 'XXX.jsp',
    // method:'GET',    //默认为POST
    params: {userId:_curUserId},     //这个传值,注意JSON格式
    success: function(response){
    alert(Ext.decode(response.responseText).msg); //解析接受JSON
    }
    });Ext.decode(response.responseText)用来解析JSON这个应该是EXTJS4的方法~
    之前的好像是Ext.util.JSON.decode(response.responseText)
    被解析的JSON请按照以下格式
    {success:,msg:,data:[{id:,name:}]}
    想解析data的id就Ext.decode(response.responseText).data.id
    明白了吗?
      

  4.   

    fanchuanzhidu
    hookee感谢你们两个的提醒。。谢了结帖子,给你们分。。