如何设置一个条件来检查数据是否为空,然后“未找到”按钮将出现,否则将被隐藏。假设客户端收到来自 API 的 Ajax 响应。
success: function(response){
var result;
if (response.data != null){
result = "dataNotNull";
} else {
result = "dataNull";
}
loadFunc(result);
}
function loadFunc(result){
$('#myTable').DataTable({
buttons: [{
text: 'Missmatch',
titleAttr: 'Download in Excel',
action: function ( e, dt, node, config ) {
func_expMissMatch();
},
}, {
text: 'Not Found',
titleAttr: 'Download in Excel',
action: function ( e, dt, node, config ) {
func_expNotFound();
},
}],
});
}
试试这个:
function loadFunc(result){
let buttons = [];
if (result === "dataNotNull") {
buttons.push({
text: 'Missmatch',
titleAttr: 'Download in Excel',
action: function ( e, dt, node, config ) {
func_expMissMatch();
},
});
}
else{
buttons.push({
text: 'Not Found',
titleAttr: 'Download in Excel',
action: function ( e, dt, node, config ) {
func_expNotFound();
},
});
}
$('#myTable').DataTable({
buttons: buttons,
});
}