0

jqgrid 不能通过设置 jsonReader 工作,重复项:false

首先我的 jqgrid 是按数组获取数据

$(listvar).jqGrid({

}
$responce = new stdClass();

    $responce -> page = $page;

    $responce -> total = $total_pages;

    $responce -> records = $count;

    $responce -> rows[$num]['id'] = $row["id"];

$responce -> rows[$num]['cell']= array("fid" => $row['fid'], "fname" => $row['fname']);

echo json_encode($responce);

它工作正常;;但我想通过键值; 然后我更改代码,以便 jqgrid 可以通过键值方式获取数据;我参考

对 jqGrid 单元格数据使用键/值对

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data


$(listvar).jqGrid({

enter code here`jsonReader : {

repeatitems : false,
   //others default value;

  },

}

我的代码:

$responce = new stdClass();

    $responce -> page = $page;

    $responce -> total = $total_pages;

    $responce -> records = $count;

 $responce -> rows[$num]['id'] = $row["id"];

$responce -> rows[$num]['cell']= array("fid" => $row['fid'], "fname" => $row['fname']);

 echo json_encode($responce);

:网络回复;

{"page":"1","total":1,"records":"1","rows":{"id":1,"cell":   [{"fid":"153","fname":"\u624b\u673a"}]}}

但是jqgrid不能显示数据;问题是什么 ?

4

2 回答 2

1

您发布的 JSON 数据包含rowsobject而不是array。这是你的问题。您应该更改您的服务器代码,以便它产生

{
    "page": "1",
    "total": 1,
    "records": "1",
    "rows": [
        {
            "id": 1,
            "cell": [
                {
                    "fid": "153",
                    "fname": "手机"
                }
            ]
        }
    ]
}

代替

{
    "page": "1",
    "total": 1,
    "records": "1",
    "rows": {
        "id": 1,
        "cell": [
            {
                "fid": "153",
                "fname": "手机"
            }
        ]
    }
}

(有关 的值,请参阅{}to的替换)[{}, ...,{}]rows

于 2013-03-22T12:18:18.660 回答
0
rows    an array that contains the actual data
  id    the unique id of the row
cell    an array that contains the data for a row

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data

所以如果你选择键值方式;单元格不应在内容 json 字符串中;

$responce -> rows[$num]['id'] = $row["id"];

$responce -> rows[$num]['cell']= array("fid" => $row['fid'], "fname" => $row['fname']);
**result:** "rows":{"id":1,"cell":   [{"fid":"153","fname":"\u624b\u673a"}]}}

改为

$responce -> rows[$num]= array("id"=>"id","fid" => $row['fid'], "fname" => $row['fname']);

reponse json:** "rows":[{"id":null,"fid":"153","fname":"\u624b\u673a"

并且 num 必须从 0 开始,因为 php 中的数组必须设置为从 0 开始,否则结果 jsonString 将是

-

  result:"rows":{"1":{"id":null,"fid":"153","fname":"\u624b\u673a"
于 2013-03-22T12:18:26.263 回答