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 6590373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:17:28+00:00 2026-05-25T17:17:28+00:00

So I’m setting a model with updated attributes. Then in my view I’m listening

  • 0

So I’m setting a model with updated attributes.

Then in my view I’m listening for a change event for this model.

When that fires I think I should use model.changedAttributes? Do I pass it a callback?

It should return a hash of all the attributes that are updated, or new? Is there anyway to know which are updated and which are new?

How should I go about updating once I have this hash of changed attributes? Parse the object to type of attribute or should I just use higher resolution listeners from the get go?

Thanks!

  • 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-25T17:17:28+00:00Added an answer on May 25, 2026 at 5:17 pm

    If your view is only showing a single attribute – for example, if it’s a checkbox showing some boolean attribute of your model – you should listen to the ‘change:attribute_name’ event for that attribute, as described in the Backbone docs.

    If your view is more complex and relies on multiple model attributes – for example if it’s a view for “To Do” list item that has “done”, “text”, and “dueDate” elements, then listen for the ‘change’ event. In this case, you can either either choose to update all of the elements on each event, or you can use changedAttributes() to determine which elements need updating.

    To illustrate …

    Update attributes using ‘change:attribute_name’ events:

    This style works well for simple views where the number of model attributes being rendered is < 3 or so. More than that and the code gets a bit cumbersome.

    model.bind('change:done', function() {
        view.doneElement.checked = model.get('done');
    });
    model.bind('change:text', function() {
        view.textElement.value = model.get('text');
    });
    model.bind('change:dueDate', function() {
        view.dueDateElement.value = model.get('dueDate');
    });
    

    Update everything on ‘change’ events:

    This style works well for complex views that render 4 or more attributes (the 3/4 attribute count is just a rough guideline, based mostly on my personal opinion).

    model.bind('change', function() {
        view.doneElement.checked = model.get('done');
        view.textElement.value = model.get('text');
        view.dueDateElement.value = model.get('dueDate');
    });
    

    The downside to this is that for any change, every element of the view is updated. So, for example, if a person marks a todo item as “done”, the text will be re-rendered, possibly losing whatever selection they may have had there. Sometimes that sort of thing is an issue, sometimes it isn’t – you’ll have to decide based on what exactly your view is doing.

    Update only what’s changed since the last ‘change’ event:

    This is the more nuanced variation of the above, and combines the best of both approaches. It updates the view elements that need updating based on the changedAttributes() results.

    model.bind('change', function() {
      var diff = model.changedAttributes();
      for (var att in diff) {
        switch(att) {
          case 'done':
            view.doneElement.checked = model.get('done');
            break;
          case 'text':
            view.textElement.value = model.get('text');
            break;
          case 'dueDate':
            view.dueDateElement.value = model.get('dueDate');
            break;
        }
      }
    });
    

    Finally, I’ll note that there’s yet another variation on this that involves having the view store a hash of what values it’s displaying, and passing that into the changedAttributes() method. That’s typically not necessary, so I won’t bore you with the details here.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.