I have a calendar day model, and in each calendar day, I have a collection of events.
If the day has events, the collection is refreshed, no problem, I show the new events. However, if the day has no events, the collection isn't being emptied, and the collection still shows the events from the day which was the last model (previous day if the user went to next day).
I've got the collection being created in the fetch success of the model, so it shouldn't be an async issue.
My model is
Myapp.Models.CalDay = Backbone.Model.extend({
url:'calendar',
initialize: function(){
this.get_cal();
},
get_cal: function(){
//calendar doesn't exist, so first time through,
Myapp.CurrentCal = this;
Myapp.cal.set({'date': new Date(),'draw_slider': true,'put_date':'today'});
Myapp.CurrentCal.Events = new Myapp.Collections.DayEvents();
this.bind('change:date',this.fetch_cal);
this.fetch_cal();
}
Myapp.CurrentCal.bind("fetched",this.get_view);
},
fetch_cal: function(){
console.log(Myapp.CurrentCal.Events);
Myapp.Calendar.fetch({
success: function(response) {
Myapp.CurrentCal.Events.reset(response.attributes.calendar_events);
Myapp.CurrentCal.trigger("fetched");
},
error: function() {
alert('error getting calendar');
}
});
},
get_view: function(){
console.log(Myapp.CurrentCal.Events);
new Myapp.Views.CalendarDay();
}
});
remove()on the view when a new day is accessed? - rudolph9response.attributes.calendar_eventsreturn ? And does it go in success callback ? - Cycloneresponse.attributes.calendar_events.length, and then reset, but it was alway returning as having the length of the old calendar day when there were events. So, same issue. Checking forresponse.attributes.calendar_events.length>0orresponse.attributes.calendar_eventsis always triggered if it has a calendar_events or not. - pedalpete