Datatables部分返回数据获取不到
例如以下响应数据因为datatables返回值的设置,红字部分获取不到,只能获取到aaData的内容:
{"iTotalDisplayRecords":161,"sums":2461.04,"iTotalRecords":161,"countstatus":161,"aaData":[{"custId":"42473927","billType":"0","createTime":"2017-01-16 18:37:02","orderDesc":"充值订单500元","orderType":"2","feeName":"SX09","fees":500,"payReturn":"4238","orderStatus":"0","payToValue":"861001006680375","id":162,"bossRequestId":"SXCHDWY0012017011618370201","payType":"44","payToType":"1","orderId":"201701161837021484563022014","openId":"o0kX6jo4A2V2VW6wUFVFWMdLVMpk"},{"custId":"42473927","billType":"0","createTime":"2017-01-16 18:36:56","orderDesc":"充值订单300元","orderType":"2","feeName":"SX09","fees":300,"payReturn":"4237","orderStatus":"0","payToValue":"861001006680375","id":161,"bossRequestId":"SXCHDWY0012017011618365676","payType":"44","payToType":"1","orderId":"201701161836561484563016763","openId":"o0kX6jo4A2V2VW6wUFVFWMdLVMpk"},{"custId":"42473927","billType":"0","createTime":"2017-01-16 18:36:52","orderDesc":"充值订单100元","orderType":"2","feeName":"SX09","fees":100,"payReturn":"4236","orderStatus":"0","payToValue":"861001006680375","id":160,"bossRequestId":"SXCHDWY0012017011618365220","payType":"44","payToType":"1","orderId":"201701161836521484563012204","openId":"o0kX6jo4A2V2VW6wUFVFWMdLVMpk"}],"sEcho":1}
我的修改如下:
Datatables的js里修改了fnServerData,添加了红色部分把响应回来的数据赋给了oSettings.jqXHR,以及添加了fnDrawCallback,在其中对响应回来的数据进行解析jQuery.parseJSON(oSettings.jqXHR.responseText),然后就可以获取到相应的值并进行显示了。
"fnServerData":function (sSource,aoData,fnCallback,oSettings) {
oSettings.jqXHR = $.Ajax({
"dataType":'json',
"type":"GET",
"url":sSource,
"data":aoData,
"success":fnCallback
});
},
"fnDrawCallback": function (oSettings) {
var json=jQuery.parseJSON(oSettings.jqXHR.responseText);//对获取到的相应数据进行解析处理
$("#sumEarn").html(json.sums);
},
新闻热点
疑难解答