gpt4 book ai didi

javascript - 未捕获的类型错误 : Object # has no method 'call'

转载 作者:行者123 更新时间:2023-11-28 08:56:38 25 4
gpt4 key购买 nike

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

顶级 View :

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"

最佳答案

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

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

@listenTo @collection, 'reset', @render

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

关于javascript - 未捕获的类型错误 : Object #<LanParties> has no method 'call' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18398408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com