我想为 DataTables 参数 aoColumnDefs 创建以下 JSON 数据:
var aryJSONColTable = [
{"sTitle": "Column00", "aTargets": [0]},
{"sTitle": "Column01", "aTargets": [1]},
{"sTitle": "Column02", "aTargets": [2]},
{"sTitle": "Column03", "aTargets": [3]}
]
然后我将变量放入我的 DataTable 变量声明中,如下所示:
var oTable = $('#report').dataTable({
"aoColumnDefs": aryJSONColTable,
"bProcessing": true,
"bServerSide": true,
"bLengthChange": true,
"bFilter": true,
"aaSorting": [[ 3, "desc" ]],
"sScrollX": "100%",
"bScrollCollapse": true,
"bJQueryUI": true,
"sAjaxSource": "./getDataEA.php"
});
基于这个有用的讨论,我尝试了一个 JavaScript 循环来创建 JSON 数据 aryJSONColTable,如下所示:
//create JSON array for aoColumnDefs
var aryColTableChecked = ["column00", "column01", "column02", "column03"];
var aryJSONColTable = [];
for (var i in aryColTableChecked) {
aryJSONColTable.push({
"sTitle": aryColTableChecked[i],
"aTargets": [i]
});
};
我总是从上面的 JavaScript 循环中为数据“aTargets”获取值“ 1 ”,我希望为数据“aTargets”获取值 [running_index_number]。
请在这件事上帮助我。先感谢您。