Model 'changing', but it's not
I have a view:
class FancyView extends Backbone.View
template: #fancytemplate
initialize: () ->
@add()
@model.bind('change', @update)
add: () ->
$(@el).html($(@template).tmpl(@model.toJSON())).prependTo('#fancy')
update: () ->
$(@el).html($(@template).tmpl(@model.开发者_如何学GotoJSON()))
When a change comes in logging @model.changedAttributes() in update shows changes under data but logging @model still shows the old data and thus nothing changes on update.
Why is @model still the old data?
It would be nice to see more... what does the template look like? What templating engine are you using?
I can say that I see one problem off the bat... you need to use the "fat arrow" (=>) instead of (->) for your update function. If you don't, @el, @template and @model will be in the wrong context when the event fires.
update: =>
$(@el).html($(@template).tmpl(@model.toJSON()))
加载中,请稍侯......
精彩评论