我正在通过以下方式获取数据
0: {p3_WoNo: "50446689"}
1: {p3_WoNo: "10842556"}
2: {p3_WoNo: "210001"}
3: {p3_WotType: "2"}
4: {p3_WotType: "2"}
5: {p3_WotType: "2"}
这里的头不是固定的,它总是在不同情况下变化。我绑定绑定动态绑定到下面的jQuery数据表。我通过以下代码为表创建标题和正文。
具有行的数据表未绑定。
未给定error.length
。当标头不固定时,如何绑定数组数据jquery数据表。
function bindDataInlabel(result, wotype) {
if ($.fn.DataTable.isDataTable('#customSearch')) {
$("#customSearch").DataTable().destroy();
}
var UserId = localStorage.UserId;
var WOValue = [];
var options = '';
//var customSearch=
var tableBody = "";
var tableHead = "";
var columns = [];
var result = result;
var wotype = wotype;
$("#customSearch thead").empty();
$("#customSearch body").empty();
customSearch = $("#customSearch").dataTable({
"info": false,
"bInfo": true,
"bProcessing": false,
"iDisplayLength": 10,
// "lengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]],
"bFilter": false,
"bSearchable": false,
"aaSorting": [],
"dom": 'B<lfrtip>',
"bProcessing": true,
"ajax": {
type: 'GET',
"url": P3Server + 'CustomSearch/labeldata?Userid=' + UserId + '&dataLabel=' + result + '&woType=' + wotype,
"dataSrc": function (data) {
tableBody = tableBody + "<tr>";
for (var prop in data.LabelData[0]) {
if (data.LabelData[0].hasOwnProperty(prop)) {
// Append properties such as email, fname, lname etc.
tableBody = tableBody + ("<th>" + prop + "</th>");
// Also keep a list of columns, that can be used later to get column values from the 'data' object.
columns.push(prop);
}
}
tableBody = tableBody + "</tr>";
// Create the data rows.
if (data.LabelData.length>0) {
data.LabelData.forEach(function (row) {
// Create a new row in the table for every element in the data array.
tableBody = tableBody + "<tr>";
columns.forEach(function (cell) {
// Cell is the property name of every column.
// row[cell] gives us the value of that cell.
tableBody = tableBody + "<td>" + row[cell] + "</td>";
});
tableBody = tableBody + "</tr>";
});
$("#customSearch").append(tableBody);
}
}
},
"fnInitComplete": function (oSettings) {
},
"buttons": [
{
extend: 'excelHtml5',
title: 'Documents List'
},
]
})
}
如何修复此错误以及如何导出到该数据表的excel中。我正在成功获取数据,但是无法转换为绑定数据。
成功执行ajax调用后,数据将绑定data.labelData