Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从JSON操作结果设置struts2jquery网格列名_Jquery_Jqgrid_Struts2 - Fatal编程技术网

如何从JSON操作结果设置struts2jquery网格列名

如何从JSON操作结果设置struts2jquery网格列名,jquery,jqgrid,struts2,Jquery,Jqgrid,Struts2,我有一个返回JSON结果的操作 {"columns":["coupon","CM","CM+1","CM+2","CM+3"],"couponList":[{"coupon":3.0,"CM":"88.2323","CM+1":"89.45","CM+2":"132.3128125","CM+3":"32.82"},{"coupon":3.5,"CM":"25","CM+1":"3125","CM+2":"333","CM+3":"5"}],"Caption":"30 Yr Fixed"} 我

我有一个返回JSON结果的操作

{"columns":["coupon","CM","CM+1","CM+2","CM+3"],"couponList":[{"coupon":3.0,"CM":"88.2323","CM+1":"89.45","CM+2":"132.3128125","CM+3":"32.82"},{"coupon":3.5,"CM":"25","CM+1":"3125","CM+2":"333","CM+3":"5"}],"Caption":"30 Yr Fixed"}
我能够用数据填充网格。如何使用JSON结果中返回的“columns”、“caption”属性填充列名和标题

我正在使用S2Jquery标记库@JSP

    <%@taglib prefix="s" uri="/struts-tags"%>
    <%@taglib prefix="sj" uri="/struts-jquery-tags"%>
    <%@taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
    <link rel="stylesheet" href="../css/jqgrid_gcpm.css">
    <link rel="stylesheet" href="../css/gcp.css">
<sj:head />

<s:url id="actionurl" action="testAction">
    <s:set var="caption" value="Caption" />
</s:url>

<sjg:grid id="gridtable" caption="%{caption}" dataType="json"
    href="%{actionurl}" pager="false" gridModel="couponList"
    rowNum="-1" rownumbers="false" altRows="true" autowidth="true"
    resizable="true" shrinkToFit="true">
    <sjg:gridColumn name="coupon" index="coupon" title="Coupon"
        sortable="false" width="30" />
    <sjg:gridColumn name="CM" title="CM" sortable="false"
        formatter="htmlFormatter" />
    <sjg:gridColumn name="CM+1" title="CM+1"
        sortable="false" formatter="htmlFormatter" />
    <sjg:gridColumn name="CM+2" title="CM+2"
        sortable="false" formatter="htmlFormatter" />
    <sjg:gridColumn name="CM+3" title="CM+3"
        sortable="false" formatter="htmlFormatter" />
</sjg:grid>

<script type="text/javascript">
    function htmlFormatter(cellValue, opts, rowObject) {
        if (cellValue == null) {
            return '';
        }
        else {
            return cellValue;
        }
    }
</script>

函数htmlFormatter(cellValue、opts、rowObject){
if(cellValue==null){
返回“”;
}
否则{
返回单元格值;
}
}

我也遇到了同样的问题,我的解决方案是:

var myfirstrow = {description:"1"};
$("#cashReceiptLines").jqGrid('addRowData',"1", myfirstrow);
这是我的网格

<sjg:grid
id="cashReceiptLines"
caption="Cash receipt lines"
gridModel="cashReceiptLines"
rowNum="15"
width="860"
dataType= "local"
rownumbers="true">
<sjg:gridColumn name="description" index="description" title="Description"/>
</sjg:grid>

亚历克斯·维森特·查孔·吉梅内斯
亚历克斯。chacon@software-colombia.com

您是在使用S2 jquery标记库还是在编写javascript?如果前者发布JSP,如果后者删除问题中提到的S2并显示脚本。我使用的是S2Jquery标记库。谢谢Alex Vicente。我开始使用jqGrid本身,而不是s2j网格。现在,直接在操作中填充列的标签。这篇文章中的工作代码:我将尝试你所做的方式,并让你知道。再次感谢。