问题
I try to store a record based on a dayClick event out of the jquery fullcalendar. According to the consol log the date is provided as: locale: Object, _d: Date 2015-03-19T00:00:00.000Z, then I pass it to ce.start and ce.end, when I check the database I have 'Invalid date' as value in calevnt.start and calevent.end --- What's wrong here?
On the client:
Template.calendar.helpers({
options: function() {
return {
lang: 'de',
dayClick:function(date,allDay,jsEvent,view){
var ce = {};
ce.start = date;
ce.end = date;
ce.color = 'red';
ce.className = 'todo';
ce.project = Session.get('active_project');
ce.title = ' Jour Fixe2';
ce.owner = Meteor.userId;
console.log(date,allDay,jsEvent,view);
Meteor.call('addCalEvent',ce);
}
}
}
});
On the server:
'addCalEvent': function (calevent) {
if (!calevent.type) {
calevent.type = 'milestone';
}
return Calevents.insert(calevent);
},
回答1:
try
Template.calendar.helpers({
options: function() {
return {
selectable: true,
selectHelper: true,
lang: 'de',
select: function(start, end, allDay) {
var ce = {};
ce.start = start.format(); // return moment date
ce.end = end.format(); // return moment date
ce.color = 'red';
ce.className = 'todo';
ce.project = Session.get('active_project');
ce.title = ' Jour Fixe2';
ce.owner = Meteor.userId;
console.log(start, end);
Meteor.call('addCalEvent',ce);
}
}
}
});
来源:https://stackoverflow.com/questions/29117863/invalid-data-in-mongodb-after-insert-of-an-iso-data