页面
大家都知道,easyui官方的是调用json文件的url
但若指向后台生成json的url也应该行的啊,但却出现了问题,
url指定方法是运行了,但前台却无数据 <script>
$(function(){
    alert(111);
$('#test').datagrid({
title:'My Title',
iconCls:'icon-save',
width:600,
height:350,
nowrap: false,
striped: true,
collapsible:true,
url:'ajaxGriduser.jspx',
sortName: 'uid',
sortOrder: 'desc',
后台方法 public String ajaxGrid() throws Exception{
userList=userDao.getAllUsers();

Map<String, Object> map=new HashMap<String, Object>();

//JSONArray jsonArray=JSONArray.fromObject(userList);
map.put("total", userList.size()+1);
map.put("rows", userList);

JSONArray jsonArray=JSONArray.fromObject(map);

HttpServletResponse response=(HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
//必须加上,防止前端从JSON中取出的数据成乱码
response.setCharacterEncoding("UTF-8");  


    PrintWriter out=response.getWriter();
out.print(jsonArray.toString());
System.out.println(jsonArray);

return null;
}后台打印json:
[{"total":7,"rows":[{"addressList":[],"uid":1,"uname":"tom","upwd":"123"}.....是json的格式不正确,还是???

解决方案 »

  1.   


    idField:'uid',
    frozenColumns:[[
                    {field:'ck',checkbox:true},
                    {title:'uid',field:'uid',width:80,sortable:true}
    ]],
    columns:[[
    {field:'uname',title:'Name',width:120},
    {field:'upwd',title:'Pwd',width:120,rowspan:2,sortable:true,
    sorter:function(a,b){
    return (a>b?1:-1);
    }
    },
    ]],
      

  2.   

    数据格式不正确,应该是[{total:7,rows:[{addressList:[],uid:1,uname:"tom",upwd:"123"}.....可以前台转换一下格式