使用DataTables插件我试图做的是:
GetData1
var dataQuery1
GetData2
dataQuery1
行添加到表格从函数GetData1
获取数据需要一段时间。因此,dataQuery1
[dataQuery1.length显示为零]中没有数据存储。我以为drawCallback
应该照顾这个。相反,我得到错误:
无法读取未定义的属性“数据”。
var resourcetable = $('#table').DataTable({
"ajax": {
"url": "QueryDataService.asmx/GetData1",
"dataSrc": ""
},
"columns": [
{ "data": "Column1" },
{ "data": "Column2" },
{ "data": "Column3" }
],
"drawCallback": function (settings) {
var dataQuery1 = resourcetable.data(); //Point of Failure
alert('The table has ' + dataQuery1.length + ' rows');//Shows zero rows
resourcetable.ajax.url("QueryDataService.asmx/GetData2").reload();
resourcetable.rows.add(data).draw()
});
在步骤1完成后,是否仍然执行步骤2,3,4?
答案 0 :(得分:0)
为了他人的利益分享我的最终解决方案。
var set1 = $.ajax({
url: "Url1.asmx/GetData1",
type: "GET",
dataType: "json"
});
var set2 = $.ajax({
url: "Url2.asmx/GetData2",
type: "GET",
dataType: "json"
});
$.when(set1, set2).done(function (dataset1, dataset2) {
var data = $.merge(dataset1[0], dataset2[0]);
$('#table').DataTable({
"aaData": data,
"aoColumns": [
{ "data": "Column1" },
{ "data": "Column2" },
{ "data": "Column3" }
]
});
});