更新
这是一个愚蠢的错字。我是Backbone.Model.extend
用来收藏的。掌心
试图遍历一个集合,但我认为我错误地填充了它或其他东西:
RecentContent = Backbone.View.extend
initialize: ->
@collection = new ContentAPI.ContentCollection()
@collection.fetch
success: (collection, response, options) =>
console.log @collection
# d {attributes: Object, _escapedAttributes: Object, cid: "c4", changed: Object, _silent: Object…}
# property `attributes` contains Objects from server
console.log @collection.models # undefined
@render()
#---------------------
render: ->
# ERROR: Object has no method 'each'
@collection.each (model) ->
console.log model
我还注意到,如果我尝试将reset
事件绑定到@collection
(而不是从success
回调中渲染),它似乎永远不会被触发。
集合很简单:
class ContentAPI
@Content: Backbone.Model.extend {}
@ContentCollection: Backbone.Model.extend
url: "/api/content/"
model: @Content
我对 Backbone 有点陌生,所以谢谢你的帮助。:)