【问题标题】:How to load data into jqgrid based on url如何根据url将数据加载到jqgrid中
【发布时间】:2014-01-26 07:53:02
【问题描述】:

我想根据 url 将数据加载到 jqgrid 中。在edit mode 中,我根据userId 从下面的方法中获取数据。

url:'<%=request.getContextPath() %>/Admin/getAllUserOffersList/${userBean.userId }'

Addmode 中,我从以下网址获取数据

url:'<%=request.getContextPath() %>/Admin/getAllOffersList/'

我根据 userId 检查 if 条件,但无法放置,显示错误。

if (userBean.userId != null) {
    url:'<%=request.getContextPath() %>/Admin/getAllOffersList/';
} else {
    url:'<%=request.getContextPath() %>/Admin/getAllUserOffersList/${userBean.userId }';
}

当我在下面的代码中检查上述条件时,它会显示

标记 ":" 的语法错误,;预计

我只想使用一个网址

这是我的代码:

$(document).ready(function(){
//jqGrid
$("#userOffersList").jqGrid({

    url:'<%=request.getContextPath() %>/Admin/getAllOffersList/',
    url:'<%=request.getContextPath() %>/Admin/getAllUserOffersList/${userBean.userId }',
    datatype: "json",   
    colNames:['Select','Category','Offer Text','Provider Name'],
    colModel:[
        {name:'isSelect',index:'isSelect',formatter: "checkbox", formatoptions: {disabled : false},editable: true,edittype:"checkbox",editoptions:{value:'true:false', defaultValue: 'false'},sortable:false,width:50},
        {name:'category',index:'category',width:100},               
        {name:'offerText',index:'offerText',width:350},
        {name:'providerName',index:'providerName',width:250},
        ],
        rowNum:20,
        rowList:[10,20,30,40,50],
        rownumbers: true,  
        pager: '#pagerDiv',
        sortname: 'offerText',  
        viewrecords: true,  
        sortorder: "asc",
        autowidth:'true',
    });
    $('#gridContainer div:not(.ui-jqgrid-titlebar)').width("100%");
    $('.ui-jqgrid-bdiv').css('height', window.innerHeight * .55);
    $('#load_userOffersList').width("130");
    $("#userOffersList").jqGrid('navGrid','#pagerDiv',{edit:false,add:false,del:false});
    $(".inline").colorbox({inline:true, width:"20%"});
});

JSP 页面:

<div id="tabs-2">
    <div id="gridContainer" >
        <table id="userOffersList"></table>
        <div id="pagerDiv"></div>
    </div>              
</div>

【问题讨论】:

    标签: jquery html jsp url jqgrid


    【解决方案1】:

    请复制粘贴下面的代码并尝试是否可行。这应该会清除所有语法错误:

    $(document).ready(function () {
                //jqGrid
                $("#userOffersList").jqGrid({
                    <c:choose>
                    <c:when test="${not empty userBean.userId}">
                    url: '${pageContext.request.contextPath}/Admin/getAllOffersList/',
                    </c:when>
                    <c:otherwise>
                    url: '${pageContext.request.contextPath}/Admin/getAllUserOffersList/${userBean.userId}',
                    </c:otherwise>
                    </c:choose>
                    datatype: "json",
                    colNames: ['Select', 'Category', 'Offer Text', 'Provider Name'],
                    colModel: [
                        {name: 'isSelect', index: 'isSelect', formatter: "checkbox", formatoptions: {disabled: false}, editable: true, edittype: "checkbox", editoptions: {value: 'true:false', defaultValue: 'false'}, sortable: false, width: 50},
                        {name: 'category', index: 'category', width: 100},
                        {name: 'offerText', index: 'offerText', width: 350},
                        {name: 'providerName', index: 'providerName', width: 250}
                    ],
                    rowNum: 20,
                    rowList: [10, 20, 30, 40, 50],
                    rownumbers: true,
                    pager: '#pagerDiv',
                    sortname: 'offerText',
                    viewrecords: true,
                    sortorder: "asc",
                    autowidth: 'true'
                });
    
    
                $('#gridContainer div:not(.ui-jqgrid-titlebar)').width("100%");
                $('.ui-jqgrid-bdiv').css('height', window.innerHeight * .55);
                $('#load_userOffersList').width("130");
                $("#userOffersList").jqGrid('navGrid', '#pagerDiv', {edit: false, add: false, del: false});
                $(".inline").colorbox({inline: true, width: "20%"});
            });
    

    请始终尝试使用 JSTL 而不是 scriptlets

    【讨论】:

    • @udaykiran pulipati - 我已经根据您的完整代码更新了答案。请尝试并告诉我。
    • @udaykiranpulipati - 我已经更新了我的答案。清除语法错误,添加 JSTL 而不是 scriptlet。请复制粘贴该代码并尝试让我知道。手指交叉!
    • 您的代码包含错误。 jQuery中添加JSTL标签是错误的
    • 为什么会出错?它不工作吗?如果您可以添加脚本,那么添加 jstl 会更好!您的原始代码包含不好且从不推荐的 sriptlet?你能告诉我如何不应该添加jstl,除非它是一个单独的Java脚本文件(在你的情况下我不认为它是)?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-19
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多