使用Ajax将数据数组加载到数据表中 [英] Loading data array into datatables using ajax
本文介绍了使用Ajax将数据数组加载到数据表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将以下数组加载到数据表中,
I am trying to load following array into datatables,
var array= {
"rowNumber": 2,
"mailingID": 3,
"firstname": "Bruce",
"lastname": "Ballister",
"organization": "Apalachee Regional Planning Council",
"address1": "20776 Central Avenue East",
"address2": "Suite 1",
"city": "Blountstown",
"state": "FL",
"zip": 32424
}
但是,表是没有将数组加载到数据表中。另外,我可以看到阵列已被接收到浏览器的响应标签中。我想我丢失了一些东西。
But, the table is not loading the array into datatable. Also, i can see the array has been received into browser's "response" tab. I think I am missing something in it.
我的代码:
$.ajax({
type : "POST",
url : "getLabels.jsp",
data : "mailingID=" + selectedValue, // posCodeSelected
success : function(data) {
var array= data;
$(document).ready(function() {
$('#printIDs').dataTable( {
"ajax": array, /* i think change is needed here*/
"columns": [
{ "data": "rowNumber" },
{ "data": "mailingID" },
{ "data": "firstname" },
{ "data": "lastname" },
{ "data": "organization" },
{ "data": "address1" },
{ "data": "address2" },
{ "data": "address3" },
{ "data": "address4" },
{ "data": "city" },
{ "data": "state" },
{ "data": "zip" }
]
} );
} );
},
error : function(response) {
var responseTextObject = jQuery
.parseJSON(response.responseText);
}
});
小提琴链接: http://jsfiddle.net/kpqru5hm/
推荐答案
已更新 >
您使用的数组结构似乎对数据表不正确。
The structure of the array you have used seems to be incorrect for the datatables.
您的代码应就像:
HTML
<table id="printIDs" class="table">
</table>
JavaScript:
var dataSet = [
['Misc','IE Mobile','Windows Mobile 6','-','C'],
['Misc','PSP browser','PSP','-','C'],
['Other browsers','All others','-','-','U']
];
$(document).ready(function() {
$('#example').dataTable( {
"data": dataSet,
"columns": [
{ "title": "Engine" },
{ "title": "Browser" },
{ "title": "Platform" },
{ "title": "Version", "class": "center" },
{ "title": "Grade", "class": "center" }
]
} );
} );
这里是小提琴: http://jsfiddle.net/harshulpandav/kpqru5hm/2/
有关更多信息: http://www.datatables.net/examples/data_sources/js_array.html
这篇关于使用Ajax将数据数组加载到数据表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文