我不相信這是你應該如何處理你的數據。不過,我也在我的mRender函數中使用了一個AJAX數據源,如下所述。
$(document).ready(function(e){
$('.products').dataTable({
"bProcessing": true,
"sAjaxSource": window.location.protocol + "//" + window.location.hostname + '/product/getAll',
"aoColumns": [
{ "sTitle": "Pid", "bVisible" : false},
{ "sTitle": "Pname" },
{ "sTitle": "Pprice" },
{ "sTitle": "Pgroups",
"mRender" : function(data, type, full){
console.log(data, type, full);
console.log(category.getAll());
return 'test';
}
}
]
});
});
德類別物體在selfinvoking功能初始化。我用它來防止函數在每次調用函數時遠程加載數據。 它看起來像這樣:
(function(){
if(typeof category === 'undefined'){
category = {};
}
category.getAll = function(){
if(typeof category.all === 'undefined'){
$.ajax({
'type' : 'POST',
'async': false,
'url' : window.location.protocol + "//" + window.location.hostname + "/category/getAll",
'success' : function(data){
console.log(data);
category.all = data;
},
'error': function(a,b,c){
console.log("You shall not pass!",a,b,c);
alert('stop');
}
});
}
return category.all;
}
})();
我也在尋找這樣做,你有解決這個問題嗎? – 2017-06-14 06:43:50