我要疯了。出于某种原因,我的 CollectionView 没有正确呈现,尽管该集合被正确设置为主干集合,尽管一切似乎都表明它应该可以正常工作。事实上,当我从模板记录对象时,它甚至显示了正确的属性!
那么到底为什么我所在的地区没有展示收藏品呢?这是我的代码:
merchants = @model.get("merchants")
merchantsCollection = new MerchantsCollection()
merchantsCollection.reset(merchants)
storesview = new StoresView
collection: merchantsCollection
itemViewOptions: ->
templateName: "image"
storesview.render()
console.dir merchantsCollection
@storeResults.show storesview
@trigger "panel:completed"
当我登录商家集合时,我得到:
MerchantsCollection
_byId: Object
_events: Object
_listenerId: "l871"
length: 8
models: Array[8]
这是我的 CollectionView 代码:
define [
"backbone.marionette",
"helpers",
"global/views/store",
"global/views/empty"
], (Marionette, helpers, StoreView, EmptyView) ->
class StoresView extends Marionette.CollectionView
className: "js-stores js-stores-view unstyled"
tagName: "ul"
itemView: StoreView
emptyView: EmptyView
initialize: (options) ->
if options.template then @template = options.template
还有我的 ItemView 代码:
define [
"backbone.marionette",
"global/models/store",
'text!global/templates/store.html',
'text!global/templates/store-image.html'
], (Marionette, storeModel, storeTemplate, storeImgTemplate) ->
class StoreView extends Marionette.ItemView
tagName : 'li'
className : "js-item store"
template : _.template storeTemplate
events:
"click a" : "gotoStore"
collectionEvents:
"all" : "render"
initialize: (options) ->
if options.templateName and options.templateName is "image"
@template = _.template storeImgTemplate
onRender: ->
gotoCategory: (e) ->
e.preventDefault()