问题描述
我有一个本地JSON文件正在呈现到DataTable中。
表格中的所有内容都很好,但日期的显示方式如下: /Date(1350028800000)/
(10/12/2012)。
我查找了有关转换数据的 ,但是基于如何将信息呈现到DataTable中,我不确定该如何进行。 对这个有什么想法吗?
JS代码段:
import $ from 'jquery';
import admissData from '../JSON/atty-admiss.json';
import DataTable from 'datatables.net';
function loadAdmiss() {
let admissText = admissData.d.results.map(function(val) {
return {
"Status": val.admissionstatus,
// "Date of Admission": val.dateofadmission,
"Expires": val.expires,
"Classification": val.classification
}
})
let admissDate = admissData.d.results.map(function(val) {
let newDate = new Date(admissDate) { //// ?
return val.dateofadmission
}
})
$('#admissions-table').DataTable({
columns: [
{ data: "Status" },
{ data: "Date of Admission" }, // ------ DT's method of injecting relevant JSON data into each column
{ data: "Expires" },
{ data: "Classification" }
],
data: admissText, // ---------- how the JSON data enters DT
lengthChange: false,
paging: true,
pagingType: "full_numbers"
});
}
loadAdmiss();
1楼
这有帮助吗?
var admissData = {
d: {
results: [
'/Date(1350028800000)/',
'/Date(1550185211515)/',
]
}
};
var parseMicorsoftFormat = function(weirdDateFormat) {
if(typeof weirdDateFormat === 'string') { //lets assume we have a string to work with
var extractedData = !!weirdDateFormat.match(/\d+/g) ? weirdDateFormat.match(/\d+/g)[0] : null;
if(extractedData) {
return new Date(parseInt(extractedData)).toLocaleString().match(/[^,]*/)[0];
}else {
return "No numbers found"
}
}else {
return "Wrong Format"
}
};
admissData.d.results = admissData.d.results.map(date => parseMicorsoftFormat(date));