Backbone Marionette CollectionView无法渲染

时间:2013-07-15 20:07:44

标签: javascript backbone.js coffeescript marionette

我正在为此而疯狂。出于某种原因,虽然集合被正确地设置为Backbone Collection,但我的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()

0 个答案:

没有答案