问题描述
尝试在fnRowCallback内部运行函数.jQuery报告此错误:
Trying to run function inside of fnRowCallback.jQuery reports this error:
too much recursion
/js/jquery.js
Line: 4
找不到此无休止的循环.alert(aData.toSource());
显示了我要遍历的数组.
Cannot find this neverending loop.alert(aData.toSource());
shows array which i'm trying to loop through.
var clientId = 1234;
var reportData = $('#report-data').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "?go=report&do=process&action=get-report",
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push({ "name": "client_id", "value": clientId });
$.getJSON( sSource, aoData, function (json) {
fnCallback(json);
});
},
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
formatDates(nRow,aData);
},
});
function formatDates(nRow,aData) {
// alert(aData.toSource());
for(i=0; i!=aData.length; i++) {
if (aData[i].match(/^([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2}):[0-9]{2}\.[0-9]{3}$/gi)) {
reportData.fnUpdate('New Date Format', nRow['_DT_RowIndex'], i);
}
}
}
推荐答案
对于每一行,调用fnRowCallback
,调用fomatDates
,调用fnUpdate
,重绘表,调用fnRowCallback
. ..
For each row, fnRowCallback
is called, which calls fomatDates
, which is calling fnUpdate
, which redraws the table, calling fnRowCallback
...
编辑:对此进行更多考虑,强制重绘可能会再次导致递归问题.而是,将fnRowCallback中对fnUpdate的调用替换为:
Thinking about this more, forcing a redraw may cause the recursion problem all over again. Instead, replace the call to fnUpdate in your fnRowCallback to this:
$(nRow).find('td:eq(' + i + ')').text('New Date Format');
这会将第i个TD元素的文本更新为新日期格式",这就是您想要执行的操作.
This will update the text of the i-th TD element to 'New Date Format', which is what it appears you're wanting to do.
这篇关于数据表:fnRowCallback内部的自定义函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!