Fighter_wjl
2015-11-21 15:07
采纳率: 100%
浏览 6.2k
已采纳

Easyui datagrid不显示数据

刚接触easyui,不太熟,根据datagrid的格式拼装了数据,无法显示到datagrid里,但是在jsp里面创建一个var变量就可以显示,求大牛帮忙看下

JSP页面代码:

 $(function() {
    //alert(getParasFromUrl("selectType"));
    //alert(getParasFromUrl("objectID"));
    //初始化表格内容
    $('#dataList').datagrid({
        title : 'IP地址详情',
        //data:dataGrid,
        method : 'post',
        singleSelect : true,
        height : 370,
        fit : true,
        fitColumns : true,
        striped : true,
        collapsible : true,
        //url : "/jsp/jcss/IPQueryDetailAction.do?operation=queryIPFromDB",
        url : "/InfoMgr/jsp/jcss/IPQueryDetailAction.do?operation=query&selectType="+getParasFromUrl("selectType") + "&objectID=" + getParasFromUrl("objectID"),
        sortName : 'IP',
        pageSize: 50, //每页显示的记录条数,默认为10
        pageList: [30, 50, 100, 200, 300],  //分页显示选项
        sortOrder : 'asc',
        remoteSort : false,
        idField : 'ID',
        pagination : true, // 显示分页
        rownumbers : true, // 显示行号
        columns : [ [
                    {field : 'ID', title : '序号', width : 20, sortable : true, halign : 'center'},
                    {field : 'IP', title : 'IP', width : 100, sortable : true, halign : 'center'},
                    {field : 'HOSTNAME', title : '主机名称', width : 100, sortable : true, halign : 'center'},
                    {field : 'GATEWAY', title : '网关', width : 80, sortable : true, halign : 'center'},
                    {field : 'USEFOR', title : '用途', width : 120, sortable : true, halign : 'center'},
                    {field : 'PROPOSER', title : '申请人', width : 120, sortable : true, halign : 'center'},
                    {field : 'CREATEDATE', title : '申请时间', width : 120, sortable : true, halign : 'center'},
        ] ],
        onLoadSuccess : function() {
            //alert('OK');
            //$('#dataList').datagrid('reload');
            //$('#dataList').datagrid('clearSelections'); // 一定要加上这一句,要不然datagrid会记住之前的选择状态,删除时会出问题
        },
        onDblClickRow: function (rowIndex, rowData) {

        },
        onClickRow: function (rowIndex, rowData) {

        },

    });
});

后台数据拼装:

    public List getIPSegFromDB(String ID){
        System.out.println("call getIPSegFromDB");
        List<String> lstIPs = new ArrayList<String>();

        StringBuffer sb = new StringBuffer();
        sb.append("{\"total\":28,\"rows\":[");
        sb.append("{\"ID\":\"1\",\"IP\":\"192.168.1.1\",\"HOSTNAME\":\"test\",\"GATEWAY\":\"192.168.1.254\",\"USEFOR\":\"测试\",\"PROPOSER\":\"11\",\"CREATEDATE\":\"2015-11-21\"},");
        sb.append("{\"ID\":\"2\",\"IP\":\"192.168.1.2\",\"HOSTNAME\":\"test\",\"GATEWAY\":\"192.168.1.254\",\"USEFOR\":\"测试\",\"PROPOSER\":\"111\",\"CREATEDATE\":\"2015-11-21\"}");
        sb.append("]}");

        lstIPs.add(sb.toString());
        return lstIPs;
    }

返回json:

 response.getWriter().print(JSONArray.fromObject(qis.getIPSegFromDB(objectID)).toString()); 

鼓捣一晚上了没查出问题来,但是按照下面的格式写到jsp页面里,就能显示出来。。。。求解啊。。。

 var dataGrid = {"total":28,"rows":[
    {"ID":"1","IP":"192.168.1.1","HOSTNAME":"test","GATEWAY":"192.168.1.254","USEFOR":"测试","PROPOSER":"111","CREATEDATE":"2015-11-21"},{"ID":"2","IP":"192.168.1.2","HOSTNAME":"test","GATEWAY":"192.168.1.254","USEFOR":"测试","PROPOSER":"111","CREATEDATE":"2015-11-21"},
    {"ID":"1","IP":"192.168.1.1","HOSTNAME":"test","GATEWAY":"192.168.1.254","USEFOR":"测试","PROPOSER":"111","CREATEDATE":"2015-11-21"},{"ID":"2","IP":"192.168.1.2","HOSTNAME":"test","GATEWAY":"192.168.1.254","USEFOR":"测试","PROPOSER":"111","CREATEDATE":"2015-11-21"}
                           ]};
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • Fighter_wjl 2015-11-23 06:08
    已采纳

    终于解决了,后台print的方法写的有问题,应该用JSONObject.fromObject(String),不能用JSONArray.fromObject(String),关闭问题

    点赞 评论
  • Robot-S 2015-11-21 15:13

    在我正确的按照例子从后台s......
    答案就在这里:easyui datagrid数据不显示
    ----------------------Hi,地球人,我是问答机器人小S,上面的内容就是我狂拽酷炫叼炸天的答案,除了赞同,你还有别的选择吗?

    点赞 评论
  • devmiao 2015-11-21 15:34

    看下是不是json的解析不正确

    点赞 评论
  • 浏览器访问url : "/InfoMgr/jsp/jcss/IPQueryDetailAction.do?operation=query&selectType="+getParasFromUrl("selectType") + "&objectID=" + getParasFromUrl("objectID")这个地址看输出什么

    点赞 评论
  • Fighter_wjl 2015-11-22 04:30

    图片说明

    显示出来是一个空行

    点赞 评论
  • sinat_31535993 2015-11-23 01:33

    JSONArray.fromObject()这个方法好像解析不了集合吧

    点赞 评论

相关推荐 更多相似问题