2013-11-20 43 views
0

我收到了一个'Missing itemViewContainer'错误,我并不期待。我的模块如下所示:木偶:意外失踪itemViewContainer

@App.module 'InstagramApp.List', (List, App, Backbone, Marionette, $, _) -> 

    class List.ItemView extends Marionette.ItemView 
     template: '#instagram_item_template' 

    class List.CompositeView extends Marionette.CompositeView 
     el: '#bb-instagram' 
     className: 'large-3 medium-6 columns projects__project' 

     events: 
      'click .js-next-photo': 'handleNextClick' 
      'click .js-prev-photo': 'handlePrevClick' 

     handleNextClick: (e) -> 
      e.preventDefault() 
      console.log 'next photo' 

     handlePrevClick: (e) -> 
      e.preventDefault() 
      console.log 'previous photo' 

     template: '#instagram_list_template' 
     itemView: List.ItemView 
     itemViewContainer: '#bb-photos-container' 

而且我的模板看起来像这样:

<script id="instagram_list_template" type="text/template"> 
    <div class="bg-pattern photos"> 
     <div class="photos__inner"> 
      <h4 class="photos__header">I.Instagram</h4> 
      <div id="bb-photos-container"></div> 
      <a href="#" class="photos__button photos__button--next js-next-photo"><img src="/assets/img/vendor/photos-btn-next.png" alt=""></a> 
      <a href="#" class="photos__button photos__button--prev js-prev-photo"><img src="/assets/img/vendor/photos-btn-prev.png" alt=""></a> 
     </div> 
    </div> 
</script> 

所以我#bb-photos-container元素显然是定义...有什么想法,什么是怎么回事?

我在这里称之为:

@App.module 'InstagramApp.List', (List, App, Backbone, Marionette, $, _) -> 

    List.Controller = 

     listPhotos: -> 

      photos = App.request 'photo:entities' 
      instagramView = new List.CompositeView({ collection: photos }) 

      $('#bb-projects-list').append(instagramView.render()) 

回答

0

你为什么要定义el?如果您将该视图追加到#bb-projects-list我猜你希望它是从模板创建的,而不是从现有元素中获取。

尝试删除该行

el: '#bb-instagram'

1

无需设置EL在这种情况下对List.CompositeView

那么你可以做

$('#bb-projects-list').append(instagramView.render().el)

一个更好的方法将将bb-projects-list定义为一个区域,然后调用

this.bbProjectsList.show new List.CompositeView({ collection: photos })