开发者

How do you use a JSON string or JSON object with jqGrid?

开发者 https://www.devze.com 2023-01-14 11:11 出处:网络
My jqGrid is work when my JSON data is in a static file, but if I copy the data to a var and then try to load the var into the jqGrid\'s url it doesn\'t show.

My jqGrid is work when my JSON data is in a static file, but if I copy the data to a var and then try to load the var into the jqGrid's url it doesn't show.

Can you pass a string into jqGrid

e.g. This works:

function GetJSON() {
    var jsonFile = "EntityWithChildren.json";
    return jsonFile;//returning a file works fine.
}

$("#jsonmap").jqGrid({
    url: GetJSON(),
    datatype: 'json',

this doesn't:

function GetJSON() {
    var json = '{"page":"1","total":"10",   "records":"10", "Entities": [       {"Fields":["Entity1", "field1", "11"]},     {"Fields":["", "field2", "22"]},        {"Fields":["Entity2", "field3", "33"]},     {"Fields":["ChildEntity1", "cfield1", "111"]}   ]}';
    return json; //doesnt work

}

$("#jsonmap").jqGrid({
    url: GetJSON(),
    datatype: 'json',
    //datatype: 'jsonstring',/开发者_如何学Go/this doesnt work either


got it. need to use datastr instead of url

datatype: 'jsonstring',
datastr: GetJSON(),
0

精彩评论

暂无评论...
验证码 换一张
取 消