0

I am trying to make a date picker with a bunch of events that I pull from an rss feed. To make the datepicker I pretty much copy this post: jQuery UI Datepicker : how to add clickable events on particular dates?

The issue I am having is that I keep getting the error event.Date is undefined. I think this may be because of how I am passing in the dates. The dates come from a collection of strings on page load, that are converted like this:

//Convert objects
currentEventInformationString = JsonConvert.SerializeObject(currentStoreEventInformation);
eventDatesString = JsonConvert.SerializeObject(storeEventDates);

Where currentEventInformationString is a collection of strings containing a title, description, and link and eventDateString is a collection of strings that are dates (I get it from a method that returns date.ToShortDateString();

I then add all of my dates to an event array like so (in js):

//Adds each event to the date picker
for (var x = 0; x < eventDates.length; x++) {
    //Adds event
    events[x] = [{ Title: currentEvents[x].title.toString(), Date: new Date(eventDates[x].toString()) }];
}

I have then tried running a console.debug(events[x].Title + " " + events[x].Date); but every time I undefined undefined

When I run a debug like this: console.debug(currentEvents[x].title.toString() + " " + eventDates[x].toString()); I get the correct values so I know that that is not the issue. Any suggestions?

Also: I know that the question seems vague so I tried to include as much sample code as I thought was relevant. If you need more let me know. To see how the date picker is made look at the link.

Edit Here is how I declare events:

//Current event
var events = new Array(eventDates.length);
1
  • I added in how I declare events in the edit. And after running console.log(events) I found that events is getting filled with the correct information Commented Apr 14, 2011 at 18:54

1 Answer 1

0

I think you have a stray set of brackets. This:

events[x] = [{
    Title: currentEvents[x].title.toString(),
    Date: new Date(eventDates[x].toString())
}];

Is assigning an array that contains one object literal to events[x] but I think you just want to assign an object to events[x]:

events[x] = {
    Title: currentEvents[x].title.toString(),
    Date: new Date(eventDates[x].toString())
};
Sign up to request clarification or add additional context in comments.

1 Comment

Yea that was the issue. I am still getting errors, but at least there different ones now. Thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.