How can I access the view from a model in backbone.js.
I would love to re-render the view on model.change().
Adding views to the model's attribute is a no-no.
Why would you need to access the view from model on its change?
In your view, simply bind:
this.model.bind('change', this.modelChanged, this) // (event, function, context)
and from now on, when your model changes, your view's modelChanged
method will be called automatically.
in version >0.9, the proper syntax will be like this in the view.
this.model.on('change', this.modelChanged, this) // (event, function, context)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With