jqGrid的不具约束力的数据 [英] Jqgrid not binding data
问题描述
我正在从WebService的JSON响应如下
的Json完全返回的数据。数据看起来像
{\"d\":\"[{\\\"ID\\\":2,\\\"$c$c\\\":\\\"my$c$c\\\",\\\"Name\\\":\\\"Myname\\\",\\\"PassWord\\\":\\\"A\\\",\\\"ClientLevel\\\":0,\\\"DeptNo\\\":\\\"\\\",\\\"DeptName\\\":\\\"\\\"},{\\\"ID\\\":3,\\\"$c$c\\\":\\\"my$c$c\\\",\\\"Name\\\":\\\"ly1\\\",\\\"PassWord\\\":\\\"mypassword\\\", .......但没有约束力我的jqGrid。
和我有以下的jqGrid code
的jQuery(#列表2)。jqGrid的({
MTYPE:'POST',
网址:myservice.asmx / GetQueryInfo serializeGridData:功能(POSTDATA){
返回JSON.stringify({
表名:表名,
ColumnList:COLUMNNAMES
});
}, ajaxGridOptions:{的contentType:应用/ JSON的;字符集= UTF-8},
jsonReader:{
repeatitems:假的,
根:'D',
页:功能(OBJ){返回1; },
总:函数(OBJ){返回1; },
记录:函数(OBJ){返回obj.toString()的长度。 }
},
数据类型:JSON,
colNames:['身份证','code','名','密码','ClientLevel','DEPTNO','DEPTNAME'],
colModel:
{名:ID,宽度:55},
{名:code,宽度:90},
{名:姓名,宽度:100},
{名:密码,宽度:80},
{名:ClientLevel,宽度:80},
{名:DEPTNO,宽度:80},
{名:DEPTNAME,宽度:150}
]
AUTOEN code:真的,
GridView控件:真实,
的rowNum:10,
loadonce:真实,
rowList:[10,20,30],
呼叫器:#pager2',
sortname:'ID',
viewrecords:真实,
排序顺序:ID,
标题:JSON示例,
loadError:功能(jqXHR,textStatus,errorThrown){
警报('HTTP状态code:'+ jqXHR.status +的'\\ n'+
textStatus:'+ textStatus +的'\\ n'+
errorThrown:'+ errorThrown);
警报('HTTP消息体(jqXHR.responseText):'+'\\ n'+ jqXHR.responseText);
}
});
。jQuery的(#列表2)的jqGrid('navGrid','#pager2',{编辑:假的,加:假的,德尔:假});
我仍然认为你使用旧code在服务器端(的WebMethod
返回字符串而不是对象),因为的 D 的价值属性是字符串。您可以在 jsonReader
使用root作为像答案 。在这种情况下它会在你的情况下也可以。所以,你可以使用
jsonReader:{
repeatitems:假的,
根:函数(OBJ){
返回的typeof obj.d ===串? $ .parseJSON(obj.d):obj.d;
}
}
I am getting Json response from WebService as below
Json returns data perfectly. Data looks like
{"d":"[{\"ID\":2,\"Code\":\"mycode\",\"Name\":\"Myname\",\"PassWord\":\"A\",\"ClientLevel\":0,\"DeptNo\":\"\",\"DeptName\":\"\"},{\"ID\":3,\"Code\":\"mycode\",\"Name\":\"ly1\",\"PassWord\":\"mypassword\", ....... but not binding my jqgrid.
and i have following Jqgrid Code
jQuery("#list2").jqGrid({
mtype: 'POST',
url: "myservice.asmx/GetQueryInfo",
serializeGridData: function (postData) {
return JSON.stringify({
TableNames: TableName,
ColumnList: ColumnNames
});
},
ajaxGridOptions: { contentType: "application/json; charset=utf-8" },
jsonReader: {
repeatitems: false,
root: 'd',
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.toString().length; }
},
datatype: 'json',
colNames: ['ID', 'Code', 'Name', 'PassWord', 'ClientLevel', 'DeptNo', 'DeptName'],
colModel: [
{ name: "ID", width: 55 },
{ name: "Code", width: 90 },
{ name: "Name", width: 100 },
{ name: "PassWord", width: 80 },
{ name: "ClientLevel", width: 80 },
{ name: "DeptNo", width: 80 },
{ name: "DeptName", width: 150 }
],
autoencode: true,
gridview: true,
rowNum: 10,
loadonce: true,
rowList: [10, 20, 30],
pager: '#pager2',
sortname: 'ID',
viewrecords: true,
sortorder: "ID",
caption: "JSON Example",
loadError: function (jqXHR, textStatus, errorThrown) {
alert('HTTP status code: ' + jqXHR.status + '\n' +
'textStatus: ' + textStatus + '\n' +
'errorThrown: ' + errorThrown);
alert('HTTP message body (jqXHR.responseText): ' + '\n' + jqXHR.responseText);
}
});
jQuery("#list2").jqGrid('navGrid', '#pager2', { edit: false, add: false, del: false });
I still think that you use old code on the server side (WebMethod
which returns string instead of object) because the value of d property is the string. You can use root in jsonReader
as function defined like in the answer. In the case it will works in your case too. So you can use
jsonReader: {
repeatitems: false,
root: function (obj) {
return typeof obj.d === "string" ? $.parseJSON(obj.d) : obj.d;
}
}
这篇关于jqGrid的不具约束力的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!