I have a view myView
and a collection myCollection
. When I add
a model to myCollection
, the add
event is triggered by myCollection
. How can I have myView
listen to that add
event?
标签:
backbone.js
相关问题
- Backbone.js PushState routes .htaccess only workin
- Updating a LayoutView's Model
- Disable Backbone.js hashes entirely, but keep push
- Is there an easy way to distribute a Flask server
- React + Backbone, Target container is not a DOM el
相关文章
- Get all models in backbone collection where attrib
- How can I dynamically set a className for a Backbo
- Nesting Views within Views in backbone js
- Backbone-relational hasmany best practices
- JavaScript error: “is not a constructor”
- Marionette + i18n in templates
- Rendering reCAPTCHA v2.0 widget within Backbone vi
- Backbone.js PUT/DELETE problems with Codeigniter R
After ver. 0.9.9 (added Dec. 13, 2012) it is recommended to use listenTO.
In line with this:
You have to bind your view to listen on the "add" event of your collection:
You can pass the collection to the view when you instantiate it, and then you can have the view bind to the add event on the collection in the initialize method.
Here's a code example
And this is how you pass the collection in when you instantiate the view