So I'm trying to form a javascript array of dates that I can feed as input to a jquery datepicker addon. My Django view is:
def autofill_featured(request):
show_id = request.GET.get('show_id')
show = Show.objects.get(id=show_id)
data = []
for listing in show.listings.all():
string = str(listing.date.month) + '/' + str(listing.date.day) + '/' + str(listing.date.year)
data.append(string)
return HttpResponse(simplejson.dumps(data))
My javascript is currently:
$(document).ready(function() {
var preselect = function () {
var results = $.ajax({
url: "/autofill_featured",
dataType: "json",
data: {show_id: $("#id_show_id").val()}
});
return results;
};
$("#picker").multiDatesPicker({
addDates: preselect()
});
If I manually specify
addDates: ['6/29/2011', '6/30/2011']
then it works, but trying to pass it the results of preselect and I get an error: "o_dates[0].getTime is not a function". According to the multiDatesPicker docs I can supply either an array of strings in the date format I used above, or an array of javascript date objects. How can I take the json that is returned by my Django view and turn it into a js array?
The docs for the jquery addon I'm trying to use are here, if it helps: http://multidatespickr.sourceforge.net/
I'm very new to JS and don't really know what's going wrong. Any ideas? Thanks for any help you can provide!