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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:50:34+00:00 2026-06-09T20:50:34+00:00

Basically I’m new to Backbone. I’m changing an attribute in my collection called limit,

  • 0

Basically I’m new to Backbone. I’m changing an attribute in my collection called “limit”, from my view. Then I’m trying to trigger an event (when an attribute has just been changed), allowing me to listen for the event and do other actions.

However, triggering an event from my collection when something is altered, and listening for that change when it occurs doesn’t work. I assume it’s something to do with the view and collection communicating with each other.. Any help would be much appreciated! Thanks

The code to trigger the event, (inside my collection) is:

@trigger("change") #TRIGGER THE EVENT

The code to change the attribute in my collection (which works) is:

@Properties.attr("limit", "1000") #Change the limit attr to "1000"

And the code to listen for the change (which doesn’t work) is:

@Properties.on("change", ->
     alert("Attribute has been changed!")
)

And the full code is:

class PropertyCollection extends Backbone.Collection
        model: Property

        constructor: ->
            super

        initialize: ->
            @_attr = {}

        #Function to change attribute of collection 
        attr: (prop, value) ->
            if value is undefined
                @_attr[prop]
            else
                @_attr[prop] = value
                @trigger("change") #TRIGGER THE EVENT

        limit: "0" #Attribute - default is set to 0



    class HomeView extends Backbone.View
        constructor: ->
            super

        initialize: ->
                @Properties = new PropertyCollection

                @Properties.attr("limit", "1000") #Change the limit attr to "1000"

                #Listen for the change
            @Properties.on("change", ->
                 alert("Attribute has been changed!")
            )

        template: _.template($('#home').html())

        render: ->
            $(@.el).html(@template)
  • 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-06-09T20:50:36+00:00Added an answer on June 9, 2026 at 8:50 pm

    You register to listen for that change AFTER you make the change

    Change attribute -> trigger event -> no-one listening -> register to listen

    So change this:

    initialize: ->
      @Properties = new PropertyCollection
    
      @Properties.attr("limit", "1000") #Change the limit attr to "1000"
    
      #Listen for the change after the firing of the change (why?!!!)
      @Properties.on("change", ->
        alert("Attribute has been changed!")
      )
    

    to this

    initialize: ->
      @Properties = new PropertyCollection
    
      #Listen for the change BEFORE you make it (yes yes yes!!!)
      @Properties.on("change", ->
        alert("Attribute has been changed!")
      )
    
      @Properties.attr("limit", "1000") #Change the limit attr to "1000"
    

    Hope this helps!

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

Sidebar

Related Questions

Basically I am trying to restart a service from a php web page. Here
Basically from C++ FAQ I learned that: A virtual function allows derived classes to
Basically, what I'm trying to create is a page of div tags, each has
Basically from a database I am getting data that is formatted like this nameofproject101
Basically there is a file called 8puzzle.py and I want to import the file
Basically what I'm trying to do is make a very simple vertical bullet projectile
Basically I have an iframe loaded that is accessed from the parent whenever it
Basically, what signal does '0' represent, because here I see SIGNAL numbers starting from
Basically, each time I click on a graphicsview, I'd like a new QGraphicsEllipseItem to
Basically I'm trying to improve on the Ghosts in a Pacman game I'm making.

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.