How can I wait till subscribe is ready?
When it does: Dates.find(); data is not ready, so there are no data. I need to wait
Router:
Router.route('/calendar', function () { Meteor.subscribe('clientsByNutritionist'); Meteor.subscribe('calendar'); this.render('calendar'); });
Onrendered:
Template.calendar.rendered = function () { var fc = this.$('#calendar'); this.autorun(function () { //1) trigger event re-rendering when the collection is changed in any way //2) find all, because we've already subscribed to a specific range Dates.find(); fc.fullCalendar('refetchEvents'); }); };
Helper:
Template.calendar.helpers({ events: function () { var fc = $('#calendar'); return function (start, end, tz, callback) { //find all, because we've already subscribed to a specific range var events = Dates.find().map(function (it) { return { title: it.day.toISOString(), start: it.day, allDay: true }; }); callback(events); }; }, onEventClicked: function() { return function(calEvent, jsEvent, view) { alert("Event clicked: "+calEvent.title); } } });