未捕获的TypeError:对象#<lanparties>没有方法'call'</lanparties>

时间:2013-08-23 08:36:24

标签: javascript ruby-on-rails backbone.js coffeescript

我正在尝试遍历集合中的每个模型的集合和渲染模板。我做错了什么?

顶级视图:

class App.Views.Content extends Backbone.View
  className: 'views-container'

  template:  HandlebarsTemplates['app/templates/content']

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

  renderEmptyView: ->
    v = new App.Views.Empty()
    @$('.content-wrapper').html(v.render().el)

  renderLanParties: ->
    v = new App.Views.LanParties({ collection: new App.Collections.LanParties })
    @$('.lan-list').html(v.render().el)

查看渲染集合:

class App.Views.LanParties extends Backbone.View
  className: 'lan-parties-list'

  template:  HandlebarsTemplates['app/templates/lan_parties']

  initialize: ->
    @listenTo @collection, 'reset', @render()
    @collection.fetch({ reset: true })

  render: ->
    @$el.html(@template())
    @collection.forEach @renderLanParty, @
    @

  renderLanParty: (model) ->
    v = new App.Views.LanParty({ model: model })
    @$('ul').append(v.render().el)

模特:

class App.Models.LanParty extends Backbone.Model

class App.Collections.LanParties extends Backbone.Collection
  model:  App.Models.LanParty
  url: "/lan_parties"

1 个答案:

答案 0 :(得分:0)

在App.Views.LanParties中不调用@render,更改

@listenTo @collection, 'reset', @render()

@listenTo @collection, 'reset', @render

您可能希望在App.Views.Content中实例化新的App.Collections.LanParties。