jquery easy UI datagrid+action错误分析

原先写过datagrid但是没有与action关联,这一次和action关联出现大问题

数据库查询出来的数据就是无法在datagrid中显示,action代码如下:


   public StringselectPeoOpNum(){
        try {
            VoteOptionDao voteOptionDao  = new VoteOptionDaoImpl();
            List<GridNode> gridNodeList = null;
            if(pages ==null){
                pages = new Pages();
            }
            Integer pageSize = Integer.parseInt(ServletActionContext.getRequest().getParameter("rows"));//每页显示记录
            Integer pageNumber = Integer.parseInt(ServletActionContext.getRequest().getParameter("page"));//当前页数
            pages.setPageSize(pageSize);
            pages.setCurrPageNo(pageNumber);
            VoteItemDao voteItemDao = new VoteItemDaoImpl();
            
            pages.setTotalPage(voteItemDao.countItemNum());
            gridNodeList=  voteOptionDao.selectOptionInfo(pages);
            JSONArray ja = new JSONArray();
            ja = JSONArray.fromObject(gridNodeList);
            ServletActionContext.getResponse().getWriter().print(ja);
        } catch (Exception e) {
            e.printStackTrace();
        }

          return SUCCESS;

    }

struts代码:

<action name="PeoOpNum" class="com.bdqn.action.VoteOptionAction" method="selectPeoOpNum">
                <result name="error">error.jsp</result>
                <result name="input">input.jsp</result>
            </action>

datagrid代码:

var datagrids = $("#datagrids").datagrid({
        height:"400",
        width:"820",
        url:'http://localhost:8080/Struts2_No_12/PeoOpNum',
        rownumbers:true,
        singleSelect:true,
        pagination:true,//显示底部分页栏
        pageSize:5,//默认每页记录数,pagination参数为true时才有效
        pageList:[5,10,15], //显示列表记录数的下拉框选项,pagination参数为true时才有效
        fitColumns:true,//自适应宽度,防止水平滚动
        striped:true,//隔行变色
        columns:[[
                    {field:'id',title:'id',hidden:'true'},
                    {field:'title',title:'投票标题',width:300},
                    {field:'options',title:'选项数',align:'right'},
                    {field:'participants',title:'投票人数',align:'right'},
                    {field:'opr',title:'操作',align:'center',formatter:function(){
                        return "<a href='#' style='color:red;'>参加投票</a>";
                    }}
                ]],
        onClickCell:function(index,field,v){
            if(field=="opr"){
                var id = $(this).datagrid("getRows")[index].id;
                var options = $(this).datagrid("getRows")[index].options;
                var participants = $(this).datagrid("getRows")[index].participants;
                window.location.href="http://localhost:8080/Struts2_No_12/selectVoteOptionByVsId?id="+id+"&options="+options+"&participants="+participants;
            }
        },
        onLoadError : function(a) {
            alert('加载数据失败!');
        }
    });


当时怎么都显示不出代码,于是我输出了json发现里面是有值得,表明查询无误,然后我又用现成的json文件检查datagrid,发现网页上能显示数据,这表明

jquery代码也无误,那么就只有一个问题了,传值问题,但是在servlet中out.print()的值datagrid是能接收的,于是想到了是不是struts.xml文件,我就添上了

   <result name="success" type="json">
                    <param name="root">ja</param>
      </result>

网上很多人都这么用,我不知道为什么还是不顶用,最后我想到了返回值,我将String改为了void去掉了返回值,结果行了,而struts.xml文件中的那段代码

在我这里可有可无,有也行,没有也行,知道的朋友请告知原因,谢谢


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值