Javascript 模板不使用';主干收集更改后的t重新加载

Javascript 模板不使用';主干收集更改后的t重新加载,javascript,backbone.js,Javascript,Backbone.js,我有一个视图,可以呈现一个模板条目。当模型被添加到集合movieSeats时,它会执行@collection.on('add',@appendEntry,this)部分,将模板entry添加到#entries容器中 class Movieseat.Views.Entry extends Backbone.View template: JST['movieseats/entry'] className: 'movie-frame' initialize: -> @c

我有一个视图,可以呈现一个模板
条目
。当模型被添加到集合
movieSeats
时,它会执行
@collection.on('add',@appendEntry,this)
部分,将模板
entry
添加到
#entries
容器中

class Movieseat.Views.Entry extends Backbone.View

  template: JST['movieseats/entry']
  className: 'movie-frame'

  initialize: -> 
    @collection.on('change', @render, this)
    @collection.on('add', @appendEntry, this)
    @collection.on('destroy', @render, this)
    return

  render: -> 
    $(@el).html(@template(entry: @collection))
    this

  events: ->
    "click div":"showCollection"

  showCollection: ->
    console.log @collection

  appendEntry: (entry) ->
    view = new Movieseat.Views.Entry(collection: entry)
    $('#entries').append(view.render().el)
在另一个视图中,我有一个从集合中删除模型的事件

class Movieseat.Views.MovieseatsIndex extends Backbone.View

  template: JST['movieseats/index']

  render: -> 
    $(@el).html(@template())
    this

  events: -> 
    "click li":         "addEntry" 
    "click .remove":    "destroyEntry" 

  addEntry: (e) -> 
    movie_title = $(e.target).text()
    @collection.create title: movie_title

  destroyEntry: (e) -> 
    thisid = @$(e.currentTarget).closest('div').data('id')
    @collection.get(thisid).destroy()
这也起作用,电影从集合中删除,但问题是当我从集合中删除模型时,
@collection.on('destroy',@render,This)
视图中的
项没有任何作用。我必须刷新页面才能看到删除事件的结果

更新

在这两个视图中,我都将
console.log(@collection)
添加到div元素上的单击事件中。当我点击一个div时,我得到了这个结果

Backbone.Model {cid: "c5", attributes: Object, collection: Movieseats, _changing: false, _previousAttributes: Object…}
Movieseats {length: 8, models: Array[8], _byId: Object, _events: Object, constructor: function…}` 

第一个结果来自
Entry
视图,第二个结果来自
Movieseat
视图

您是否尝试在您的收藏中收听
删除
事件,而不是
销毁


将quick console.log添加到渲染中,以检查哪些事件导致视图重新运行该功能。根据我的经验,我总是在集合上使用
重置
添加
删除
排序
事件,在单个模型上使用
更改
销毁
,等等。如果你愿意的话,从语义上讲,这对我来说更有意义。集合不会被销毁,但项目会被删除。:)

我用
remove
替换了
destroy
,但效果不大。我想我可能已经找到了问题所在。我已经更新了问题。可能是重复的