0

我有这个 ajax 代码。我还尝试了 onselectrow,格式化程序,我想如何获取行对象并将其发送到控制器,以便我的下一页可以显示行对象发送的所有详细信息。

var jq = jQuery.noConflict();

jq(document).ready(function() {
    var grid = jq("#grid");
    grid.jqGrid({
        url:'${pageContext.request.contextPath}/getRegisteredClassesData.html',
        datatype: 'json',
        mtype: 'POST', 
        colNames:['Course Name'],
        colModel:[{name:'courseName',index:'courseName', width:55, 
                formatter: function (cellvalue, options, rowObject) {
                var cellPrefix = '';
                return cellPrefix + '<a href= ${pageContext.request.contextPath}/registeredClassesDetail.phone?regNo='+ rowObject.regNo +'&courseId='+ rowObject.courseId +'">' + cellvalue + '</a>';
            }
        },],
        rowNum:5,
        height: 130,
        autowidth: true,
        pager: '#pager',
        hidegrid:false,
        viewrecord: true,
        emptyrecords: "Empty records",
        loadComplete: function() {},
        jsonReader : {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            cell: "cell",
            repeatitems: false,
            id: "id"
        }
    });

    grid.jqGrid('navGrid','#pager',
        {add:false, edit:false, del:false, search:false}
    );
}); 

从控制器,我想获取我发送的参数,即 courseId 和 regNo。但是当我在控制器中调试时,两者都是空的。我想使用这 2 个参数在域中搜索,以便显示正确的数据。请帮我。谢谢是提前。

这是页面中将显示详细信息的 ajax 代码。它几乎相同。但最重要的是我想检索数据,以便我可以以任何形式显示。

    var jq = jQuery.noConflict();

 jq(document).ready(function() {
var grid = jq("#grid");
var regNo = '<%=request.getSession().getAttribute("regNo")%>';
var courseId = '<%=request.getSession().getAttribute("courseId")%>';

grid.jqGrid({
    url:'${pageContext.request.contextPath}/getRegisteredClassesDetails.html',
    datatype: 'json',
    mtype: 'POST',
    /* postData: {
        courseId: function() { return jQuery("#courseId option:selected").val(); },
        regNo: function() { return jQuery("#regNo option:selected").val(); }
    }, */
    postData:{regNo:regNo,
        courseId:courseId},  
   colNames:['Registration #', 'Status', 
    'Course Name', 'Location', 
    'Start Date', 'Registered Person'],

    colModel:[
        {name:'regNo',index:'regNo', width:20},
        {name:'regStatus',index:'regStatus', width:20},
        {name:'courseName',index:'courseName', width:150},
        {name:'courseLoc',index:'courseLoc', width:30},
        {name:'startDate',index:'startDate', width:25},
        {name:'fullName',index:'fullName', width:30,sortable:false}],
    rowNum:5,
    rowList:[5,10,20],
    height: 200,
    autowidth: true,
    pager: '#pager',
    sortname: 'startDate',
    hidegrid:false, //disable the collapse/expand function
    viewrecord: true,
    caption:"Course Details",
    emptyrecords: "Empty records",
    //multiselect:true,
    loadComplete: function() {

    },
    jsonReader : {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        cell: "cell",
        repeatitems: false,
        id: "id"
    }
});

grid.jqGrid('navGrid','#pager',
    {add:false, edit:false, del:false, search:false}
);

});

4

1 回答 1

1

`添加如下内容

postData: {
        courseId: function() { return jQuery('#courseId').val(); },
        regNo: function() { return jQuery('#regNo').val(); }
    },`
于 2013-01-30T10:37:25.200 回答