fullCalendar how to set the events programatically -
i'm having problem setting calendar event grammatically.
i have page user can select client display event using drop down. request events via ajax call. , looks good. i'm having problem setting events in fullcalendar.
this code set events:
success: function(resp){ var r = resp.output; console.dir(r); jquery('#student').html(r.studentname); jquery('#calendar').fullcalendar( 'removeevents' ); // <= works jquery('#calendar').fullcalendar( 'events', r.events ); // <= doesn't }
this dump of ajax response:
events "[{ id: 1, title: 'acupuncture', start: new date(2013, 5, 29, 10, 00), end: new date(2013, 5, 29, 10, 30), allday: false } , { id: 2, title: 'acupuncture', start: new date(2013, 6, 30, 10, 00), end: new date(2013, 6, 30, 10, 30), allday: false } , { id: 3, title: 'chiropractor', start: new date(2013, 6, 31, 11, 00), end: new date(2013, 6, 31, 11, 15), allday: false } ] " id "1" studentname "tarah yates"
i couldn't find examples on how i'm not sure if doing right.
i noticed quotes around event list, maybe that's problem?
if that's not problem, have thoughts on why it's not working?
gwardell response needs iterated can fetch elements of array. change type of response json this:
[{ "id": "1", "title": "acupuncture", "start": "29-05-2013 10:00", //adapted date format accepted fullcalendar "end": "29-05-2013 10:30", "allday": false //you dont need adapt mistake of me. leave be. },etc, etc, etc]
notice there can simple json, can't have response complex json sub-arrays.
ps. - go , study bit of json format on net , figure out i'm sure.
not sure line, wanna create event in view while there, when switch other view disapear. want save database or whatever use store data store events. persistent , when refetchevents event apear...so jquery('#calendar').fullcalendar( 'events', 'refetchevents' );
how pass id in ajax call assuming doing json , jquery ajax
$.ajax({ type: 'post', url: _url, data: {'id': 9999, //just pass or can set function 'id':getmyid(), 'title':name, 'start':start, 'end':end, 'allday': allday, 'editable': true, }, success: function(data) { //todo stuff } });
or if have array of eventsources
var othersources = { ausencias: { url: _url, type: 'post', data:{ 'id':getmyid(), // 'id':myidvalue 'func':func, 'year':y }, cache: false, color: '#c1272d', textcolor: 'white' }}
Comments
Post a Comment