0

我有一个问题 - 我已经为每个模型创建了一个删除链接并将它从数据库中删除......但我没有设法正确设置删除事件的回调,因为它是正确的视觉显示。

class Notes.Views.ArticlesIndex extends Backbone.View.     
  render: ->  
    $(@el).html(@template())  
    @collection.each(@appendEntry)  
    this  

  appendEntry: (article)->  
    view = new Notes.Views.Article(model: article)  
    $('ul#article_list').append(view.render().el)  


class Notes.Views.Article extends Backbone.View   
  template: JST['articles/menu']    
  events:  
    'click a.delete': 'deleteEntry'   
  initialize: ->  
    # putting @model.on('destroy',@render,this) didn't help    
  deleteEntry: (event)->  
    event.preventDefault()  
    @model.destroy()

更新 !
除了@nEEbz 答案,添加@model.on('destroy',@remove,this)回调也有帮助!

4

1 回答 1

1

试试这个:

deleteEntry: (event)->
    event.preventDefault()
    @model.destroy()
    @$el.remove()
于 2013-03-01T12:45:30.750 回答