Backbone.js fetch modified event does not fire after successful selection

I have the following view:

Observation class extends Backbone.Model

class Observations extends Backbone.Collection model: Observation constructor: -> @url = _observationsUrl class ObservationsView extends Backbone.View el: $('#observations') initialize: -> _.bindAll @ @model.bind 'changed', @render @model.view = @ that = @ @model.fetch { success: -> alert('success') that.model.trigger 'changed' } render: => alert('rendering baby') class ObservationsController extends Backbone.Controller initialize: -> observations = new Observations() observationsView = new ObservationsView(model: observations) 

I bind the event with the modified model to the ObservationsView rendering method. The model is a basic collection.

Fetching fails, but the modified event does not fire. I am trying to disable manual shutdown.

Can anyone see what I'm doing wrong?

+6
source share
1 answer

The event is not called "changed." The event that is triggered after updating the model collection from the server is updated.

The change event is actually more complex. This is an event on the model that fires when you call .set() , and always includes an attribute, so you should write things like:

 this.model.bind('change:username', _.bind(this.update_username_display, this)) 

As always, the source code of backbone.js is highly readable.

+5
source

Source: https://habr.com/ru/post/891726/


All Articles