开发者

backbone.js fetch changed event not firing after a successful fetch

I have the following backbone view:

class Observation extends Backbone.Model

class Observations extends Backbone.Collection
  model: Observation

  constructor: ->
    @url = _observationsUrl

class ObservationsView extends Backbone.View
  el: $('#observations')

  initialize: -&g开发者_开发技巧t;
    _.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 am binding the model's changed event to the render method of the ObservationsView. The model is a backbone collection.

The fetch is working successfully but the changed event is not being fired. I am trying the manual trigger out of desperation.

Can anyone see what I am doing wrong?


The event isn't called 'changed'. The event triggered after the model's collection has been refreshed from the server is 'refresh'.

The 'change' event is actually more complicated. It's an event on a model that's triggered whenever you call .set(), and it always includes the attribute, so you'd write things like:

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

As always, the backbone.js source code is eminently readable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜