通過收集迭代這是一個愚蠢的錯字。我正在使用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
我有點新幹線所以謝謝你的幫助。 :)
即使找出答案,也應該選擇一個答案。 – Russ