我正在使用从 json 文件中获取数据的数据表。
var date=new Date();
var day=date.getDate();
var dataTable = $('#.main_content table').dataTable({
"bProcessing": true,
"bPaginate": false,
"bSort": false,
"bServerSide": true,
"bjQueryUI": true,
"sAjaxSource": 'sources/data.json',
"fnServerData": fnServerObjectToArray()
});
如您所见,我正在使用一个函数从 json 文件中提取数据。
fnServerObjectToArray = function () {
return function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"dataType": "json",
"success": function (json) {
var a = [];
var data = json.aoData;
for (var i = 0, iLen = data.appointments.length; i < iLen; i++) {
var inner = [];
inner.push(data.appointments[i].time);
if (data.appointments[i].CHT111[day]) {
inner.push(data.appointments[i].CHT111[day]);
inner.push(data.appointments[i].DOB[day]);
inner.push(data.appointments[i].Patient[day]);
inner.push(data.appointments[i].Visit_Reason[day]);
inner.push(data.appointments[i].Room[day]);
inner.push(data.appointments[i].Scheduled[day]);
}
else {
inner.push(data.appointments[i].CHT111.default);
inner.push(data.appointments[i].DOB.default);
inner.push(data.appointments[i].Patient.default);
inner.push(data.appointments[i].Visit_Reason.default);
inner.push(data.appointments[i].Room.default);
inner.push(data.appointments[i].Scheduled.default);
}
a.push(inner);
}
json.aaData = a;
fnCallback(json);
}
});
}
}
问题是我有一个按钮可以更改 day 变量,然后调用不起作用的 fnDraw() 方法。