2013-11-20 41 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 })