我正在使用一个名为 moment.js 的 JS 库来查找和消除 start_time 和 stop_time 之间有很大差距的事件。我一直收到这个错误 -
TypeError: moment(...) is null var stopmoment1 = moment(data.events.event[x].stop_time).format("YYYY");
啊!!!
for (var x = 0; x < data.page_size; x++) {
var position = new google.maps.LatLng( data.events.event[x]['latitude'], data.events.event[x]['longitude']);
// 年份在控制台中返回
console.log(moment(data.events.event[x].start_time).format("YYYY"));
// 但是这里说 moment 返回 null
var startmoment1 = moment(data.events.event[x].start_time).format("YYYY"); var startmoment2 = moment(data.events.event[x].start_time).format("MM"); var startmoment3 = moment(data.events.event[x].start_time).format("DD");
var startmoment = moment([startmoment1,startmoment2,startmoment3]);
var stopmoment1 = moment(data.events.event[x].stop_time).format("YYYY"); var stopmoment2 = moment(data.events.event[x].stop_time).format("MM"); var stopmoment3 = moment(data.events.event[x].stop_time).format("DD");
var stopmoment = moment([stopmoment1,stopmoment2,stopmoment3]);
if (startmoment.diff(stopmoment, 'days') > 7) { } else{
if (moment().format("YYYYMMDD") == moment(data.events.event[x].start_time).format("YYYYMMDD")) { marker.push(new google.maps.Marker({ position: position, map: map, icon: image })); marker[x].x = x;//make the marker aware of its own index google.maps.event.addListener(marker[x], 'click', function() { var div = document.createElement('div'); div.setAttribute("id", "tabs-min"); div.innerHTML = content[this.x]; $(div).tabs(); infowindow.setContent(div); infowindow.open(map, this); }); } else { marker.push(new google.maps.Marker({ position: position, map: map, icon: image1 })); marker[x].x = x;//make the marker aware of its own index google.maps.event.addListener(marker[x], 'click', function() { var div = document.createElement('div'); div.setAttribute("id", "tabs-min"); div.innerHTML = content[this.x]; $(div).tabs(); infowindow.setContent(div); infowindow.open(map, this); }); }