Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6973641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:08:02+00:00 2026-05-27T17:08:02+00:00

I am creating a Calendar app. The main view displays a single month, and

  • 0

I am creating a Calendar app. The main view displays a single month, and in each month there are views for each day.

Data in the month is represented by a collection, and each model in the collection represents each day’s data.

Now, I wanted to reduce the number of server requests to get the calendar, so each time I ask the server to get me results, I save it in an object.

var Calendar = Backbone.Router.extend({
  calendar_view  : new MonthView(),
  calendar_cache : new Object(),

  initialize:function() {
    calendar_view.display_calendar();
  }  
});

var MonthView = Backbone.View.extend({

  display_calendar : function() {
    if(calendar.calendar_cache[month]) {
      this.collection = calendar.calendar_cache[month];
      this.render();
    } else {
      // ... get the new calendar data from the server and save to the cache
    }
  }

  render:function() {
    // display calendar by building its views and rendering it.
  }
});

var cal = new Calendar();
var month = 10;

I’m not entirely sure if above is the right approach, but when I tried it, it worked well.

The model for each day and the month is simple.

var Month = Backbone.Collection.extend({
  model:Day
});

var Day = Backbone.Model.extend({});

Each day also has its view, which is built inside the “MonthView.render()” function.

var DayView = Backbone.View.extend({
  ...
});

Now, my problem is in my DayView, I bind to a model change to kick off a certain event, as below.

var DayView = Backbone.View.extend({
  initialize:function() {
    this.model.bind('change', this.highlight, this);
  },

  highlight:function() {
    console.log('This event should be fired whenever this view's model is changed!');
  }
});

But for the cached collection of models, the above binding isn’t working. I am assuming it’s something to do with binding/unbinding of views and its model events when I refresh the views.

I went through questions

Backbone.js : repopulate or recreate the view?

And also went through the article

http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/

But I’m not exactly sure what to do and how to go about this.

EDIT : I tried turning OFF the caching, but just requesting the server every time and everything works fine. So is it because there is an old view hanging around somewhere that is binding to the cached model?

EDIT : (For Thomas) rendering my “month view” is as follows. MonthView acts as a ‘parent’ view, and appends all the Day view into its “el”.

MonthView = Backbone.View.extend({
  ...
  ...
  render:function() {
    var self = this;
    this.collection.each(function(day) {
      var each_day = new DayView({ model: day });
      $(self.el).append(each_day.render().el);

      // highlight if each_day is "today", by modifying the model's attribute.
      if( day.toJSON().day == TODAY ) {
        day.set({selected:true});
      }
    }
  }
});

var TODAY = 23;

Above code works fine, when displaying the calendar for the first time, but next time I’m accessing the same calendar, “day.set({selected:true})” doesn’t seem to fire the “this.model.bind” set in the DayView file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:08:03+00:00Added an answer on May 27, 2026 at 5:08 pm

    Explications

    It’s normal that the model don’t trigger the View the next time because Backbone JS don’t change the model.

    Indeed when you do day.set({selected:true});, the model has now a property selected to true.
    So when you do once again, Backbone doesn’t modify the model because it has already the property selected to true.

    Solution

    You don’t need to modify the model to call the View’s highlight function, call it directly from the View instance :

      if( day.toJSON().day == TODAY ) {
        each_day.highlight();
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a calendar that displays a timetable of events for a month. Each
I'm creating a JavaScript based calendar control, which when showing a single day needs
I am creating a monthly calendar of events. Each day that has one or
Is there away of creating a calendar app for android from scratch using java
I am creating a calendar application. In the Events table, there are two columns,
I'm creating a mobile app in which I need to show a calendar with
I'm creating a calendar application in PHP with CodeIgniter. In the main calendar page,
Good day everyone. I am creating a calendar component, and I'm working in the
I am creating a calendar based app. I have two dates say present date,
I'm creating a little calendar app in Django. I have two model classes; Calendar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.