2012-12-19 164 views
0

可能重複:
Backbone js: How to remove extra tag in view?骨幹JS追加視圖

爲什麼每當我追加了新的骨幹以一個HTML元素,它會自動圍繞着這一觀點與<div> </div>

比如我有一個表在我的HTML頁面

<table class="table table-hover"> 

    <thead> 
     <tr> 
     <th>Column1</th> 
     <th>Column2</th> 
     </tr> 
    </thead> 

    <tbody id="tbl">  
    </tbody> 

</table> 

現在在我的骨幹控制器,I執行以下

$("#tbl").append(new tblview().render().el); 

,並在實際視圖的HTML模板我有

tblview.html

<tr> 
    <td>entry3</td> 
    <td>entry4</td> 
</tr> 

現在,當我看這個瀏覽器,並檢查HTML元素..它呈現這樣的:

<table class="table table-hover"> 

    <thead> 
     <tr> 
     <th>Column1</th> 
     <th>Column2</th> 
     </tr> 
    </thead> 

    <tbody id="tbl"> 
     <div> 
       <tr> 
       <td>entry3</td> 
       <td>entry4</td> 
       </tr> 

     </div> 
    </tbody> 

</table> 

並因此成爲所有脫節?我該如何解決這個問題? 我希望它能夠在表格中顯示沒有這些額外<div> </div>的視圖。

+0

也http://stackoverflow.com/questions/9982785/when-extending-a-backbone-view-is-there-a-way-to-not-render-a-tagname –

+0

和HTTP ://stackoverflow.com/questions/11195242/extra-wrappers-in-backbone-and-marionette –

+0

this one too http://stackoverflow.com/questions/13601966/how-to-avoid-template-wrapping-with-空中div-in-backbone –

回答

0

您的模板不需要包含tr標籤。 tblView應該有tagName設置爲tr

+0

謝謝,直接解決了我的問題:] mymy我過去1年一直在使用骨幹網,並且不知道這個... –

2

主幹自動創建一個div以環繞任何視圖。要覆蓋默認值,您需要在擴展視圖時設置tagName屬性。 http://backbonejs.org/#View-extend

Backbone.View.extend({ 
    tagName: "tr" 
}); 
+0

您是先生,是天才! –

+1

還沒有,但我很高興這有助於你! –