簡體   English   中英

JqG​​rid 不從 JSON 加載數據

[英]JqGrid not loading data from JSON

我的網站上有一個 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 與 ASP.NET MVC - 調用 ajax 啟用的 Web 服務http://www.trirand.com/jqgridwiki/doku.php ?id=wiki:retrieving_data#json_data在 JQGrid 中映射 JSON 數據)。 最簡單的方法是生成可以使用標准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"]},
  ]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM