java - JqG​​rid 不从 JSON 加载数据

标签 java javascript jquery json jqgrid

我的网站中有一个 JQGrid 插件,表格加载正常,但没有行可供编辑、选择或其他操作。它正在请求服务器,因为当我查看日志时,我看到了请求及其参数(sidx、_search、rows、sord、nd 等)。

这是 jqgrid 代码:

$(document).ready(function() {
    var lastsel;
    jQuery("#rowed3").jqGrid(
            {
                url : CONTEXT_PATH+'/ajax/getPartesByCategory.do?catid=<s:property value="categoryId" />',
                datatype: 'json',
                colNames : [ 'piezaId', 'descripcion', 'disponible'],
                colModel : [ {
                    name : 'piezaId',
                    index : 'piezaId',
                    align : "right",
                    width : 40
                }, {
                    name : 'descripcion',
                    index : 'descripcion',
                    width : 360,
                    editable : true
                }, {
                    name : 'disponible',
                    index : 'disponible',
                    width : 80,
                    editable : true
                } ],
                rowNum : 20,
                rowList : [ 20, 40, 60, 80 ],
                pager : '#prowed3',
                sortname : 'id',
                viewrecords : true,
                sortorder : "desc",
                onSelectRow : function(id) {
                    if (id && id !== lastsel) {
                        jQuery('#rowed3').jqGrid('restoreRow', lastsel);
                        jQuery('#rowed3').jqGrid('editRow', id, true);
                        lastsel = id;
                    }
                },
                editurl : "server.php",
                caption : "Piezas"
            });
    jQuery("#rowed3").jqGrid('navGrid', "#prowed3", {
        edit : false,
        add : false,
        del : false
    });
})

这是服务器返回的 JSON:

[{
  "piezaId": 486,
  "disponible": 1,
  "descripcion": "Asiento delantero LH",
  "category": {
    "categoryId": 2,
    "category": "Interior",
    "status": 1,
    "subCategories": []
  }
}, {
  "piezaId": 485,
  "disponible": 1,
  "descripcion": "Asiento delantero RH",
  "category": {
    "categoryId": 2,
    "category": "Interior",
    "status": 1,
    "subCategories": []
  }
}]

在服务器端,我使用 JAVA6、Struts2 和 GSon 来编写 json,但对于这些 ajax 调用,我只向响应写入文本/纯内容

有什么帮助吗?

最佳答案

您应该更改从服务器发送的数据格式或使用某些 jsonReaderjsonmap 技术(例如,参见 jquery with ASP.NET MVC - calling ajax enabled web servicehttp://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_dataMapping JSON data in JQGrid )。最简单的方法是生成可以使用标准 jsonReader 读取的数据(请参阅 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data ):

{
  "total": "1", 
  "page": "1", 
  "records": "2",
  "rows" : [
    {"id" :"1", "cell":["486","1","Asiento delantero LH"]},
    {"id" :"2", "cell":["485","1","Asiento delantero RH"]},
  ]
}

关于java - JqG​​rid 不从 JSON 加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3173304/

相关文章:

java - Eclipse 巨大的 CPU 峰值

javascript - 如何访问conditionizr对象?

javascript - YUI 数据表 - "Data Error."

javascript - 如何在父元素内的嵌套元素上调用 CSS 动画?

java.io.IOException : Server returned HTTP response code: 403 for URL 异常

java - HttpResponse 代码 302

javascript - 使用 underscore.js 展平对象的 javascript 数组

javascript - 使用javascript模拟点击HTML选择选项

java - 在 mvn package 之后创建指向当前 jar 包的符号链接(symbolic link)

javascript - 如何修复链中最后一个 promise 的返回类型?