我正在尝试从fnRowCallback
调用一个从AJAX请求返回数据的函数。在console.log
上可以访问数据,但是在return
上返回undefined
。这就是我正在尝试的功能,我正在尝试从getUsersCount
调用的函数fnRowCallback
。
$(document).ready(function() {
$('#match-request-list').DataTable({
"lengthMenu": [25, 50, 100],
"pageLength": 50,
"searching": false,
"bProcessing": true,
"ordering": false,
"serverSide": true,
"responsive": true,
"stateSave": true,
"stateDuration": -1,
"dom": '<"top"f>rt<"bottom"ilp><"clear">',
"ajax": {
url: "{{ url('automatch/resultset') }}",
type: "post",
data: {
"id": $('#req_id').val()
}
},
error: function() {},
"initComplete": function(settings, json) {},
"fnDrawCallback": function(settings) {
$('[data-toggle="tooltip1"]').tooltip({
content: function() {
return $('#tooltipContent').html();
}
});
},
fnRowCallback: function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$(nRow).attr({
size: aData[7],
category: aData[8],
category_group: aData[9]
}); //add id to tr rel attribute
var count = getUsersCount(aData[10], aData[9], aData[8]);
// console.log(count);
$('td:eq(5)', nRow).html('<p style="text-align:center;"' + count + '</p');
},
columns: [null, null, null, null, null, null, null, {
visible: false
}, {
visible: false
}, {
visible: false
}, {
visible: false
}]
});
});
function getUsersCount(reqId, catGrId, catId) {
getUsersCountAjax(reqId, catGrId, catId).complete(function(data) {
return data.count;
// console.log(data.count);
});
}
function getUsersCountAjax(reqId, catGrId, catId) {
return $.ajax({
data: {
reqId: reqId,
catGrId: catGrId,
catId: catId
},
url: "{{ url('/assigned-users/count') }}",
type: 'POST',
async: false,
dataType: 'json'
});
}