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

  • Home
  • SEARCH
  • 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 5972975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:44:06+00:00 2026-05-22T20:44:06+00:00

I have a chart model like this: //PSEUDO chartModel = Backbone.Model.extend({ defaults: { year

  • 0

I have a chart model like this:

//PSEUDO
chartModel = Backbone.Model.extend({
     defaults: {
         year : 1970,
         selected = ["Sweden", "Denmark"]
     }
 }

I’d now like to set both year & selected:

chartModel.set({year: 1987, selected : ["Finland"]})

But before I trigger the model change I’d like to “resolve” the changes to this unstable model. So I pass silent:true and override the set method:

chartModel.set({year: 1987, selected : ["Finland"]}, {silent:true})

//Pseudo set override
set : function(attrs, options) {

  // Extract attributes and options.
  options || (options = {});
  if (!attrs) return this;
  if (attrs.attributes) attrs = attrs.attributes;
  var now = this.attributes, escaped = this._escapedAttributes;

  [...]

  datamanager.loadNewDataIfNeeded(oldModel, newModel, callback)

I’d specifically like a data manager to “diff” the old attributes vs the new before I trigger the change event:

 callback : function(){
      chartModel.change();
 }

Now – when I know that the right data is in place – I’d like the views to render.

… But my Sidebar view that is bound to change:selected does not render?

Sidebar = Backbone.View.extend({    
    initialize: function(){
        this.model.bind("change:selected", this.render);
    }
    render : [...]
});

My questions:

  1. When triggering model.change() manually, why aren’t the individual attribute change events fired?

  2. Do I really need to override the model set method to achieve what I want to (“resolving the model when several attributes are changed at once”) or is there a better method?

  • 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-22T20:44:07+00:00Added an answer on May 22, 2026 at 8:44 pm

    My opinion based upon my understanding of what you are trying to do is this:

    • Rarely or never override the set method; not sure why you feel you have to do it in this case.

    • If you call the set method without {silent: true}, you should get events for change:year and change:selected and change. But objects have to be bound to them to get them. See the bind function.

    • If you call the change function, only the change event is triggered. The attribute level events are not triggered.

    It sounds like you should not be overriding the set method and just assure that you have proper binding in those objects that have an interest in this model’s changes. Also, eliminate the silent: true passage.

    Here’s some code based upon your comment:

    Thing = Backbone.Model.extend({
    
      initialize: function(attributes, options) {
        this.bind('change:a', this.calculateC);
        this.bind('change:b', this.calculateC);
      },
    
      canCalculateC: function() {
        return this.get('a') == someMagicalValueForA && 
               this.get('b') == someMagicalValueForB;
      },
    
      calculateC: function() {
        if (!this.canCalculateC()) return;
        var self = this;
        $.post('some/url', function(data) {
          var c = // extract value for c
          this.set({c: c});  // which triggers the 'change:c' and 'change' events
        });
    
    
      }
    

    });

    ThingView = Backbone.View.extend({
    
      initialize: function(options) {
        this.model.bind("change:c", this.render);
      }
    
      ...
    
    });
    

    where the model itself is binding to change events for the a and b attributes and handling those by checking to see if it can calculate c, then doing so, then setting the value of c based upon the Ajax return. The model will then trigger ‘change:c’ for a view to observe. I sketched in the view plumbing which would enable this.

    This is untested code, but hopefully conceptually close.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a class definition that looks something like this class someClass(models.Model): field1 = models.ForeignKey('other_app.field4')
I have this model and modelform: class Comment(models.Model): text = models.CharField(max_length=100) def clean_text(self): print
I have one list, which the item render it`s like this: link . But
I have a cart model class that has a List property like so: public
I have been trying the model-first method when designing my application. We usually like
I have a chart in a Worksheet in Excel and I have a macro
I have a chart with a series that denotes a large set (1000's) of
I have a chart (in bitmap format) that I'm trying to render to a
In my MVC project I have a chart being generated on my view as
I have a line chart that is updated every so and so seconds, similar

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.