我刚开始学习dataTables。
是否可以在DataTable渲染函数中使用getJson()来渲染表数据?
我从console.log(类别)获取未定义;此刻。
我在这里错过了什么吗?
function loadHelpdeskTickets(id) {
$.getJSON(HELPDESKTICKETS_URL + "?filter[where][customerId]=" + id, function(data) {
var table = $('#helpdesk_table').DataTable({
data: data,
"order": [
[1, "desc"]
],
"processing": true,
"bLengthChange": true,
"bFilter": true,
"bInfo": true,
"paging": true,
"columns": [{
data: "id"
},
{
data: "ticketOpen",
render: function(data, type, row) {
date = new Date(data);
return date.toLocaleString("en-GB");
}
},
{
data: "category",
render: function(data, type, row) {
var category;
$.getJSON(HELPDESKQUESTIONS_URL + "?filter[where][id]=" + data, function(data) {
$.each(data, function(key, val) {
console.log(val.type);
category = val.type;
});
});
console.log(category);
return category;
}
},
{
data: "userId"
},
{
data: "installerId"
}
]
});
});
}