0

Possible Duplicate:
Backbone js: How to remove extra tag in view?

How come whenever I append a new backbone view to an HTML element, it automatically surrounds this view with a <div> </div>?

For example I have a table in my HTML page

<table class="table table-hover">

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

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

</table>

Now in my backbone controller, I perform the following

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

and in the actual view's HTML template I have

tblview.html

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

Now when i look at this in the browser, and inspect the html element.. it renders like this:

<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>

and thus is becomes all out of line? How can I fix this issue?? I want it to render the view without these extra <div> </div> in the table.

Community
  • 1
  • 1
Tyler Evans
  • 567
  • 1
  • 8
  • 25

2 Answers2

2

Backbone automatically create a div to surround any view. To overwritte the default, you need to set the tagName attribute when you extend a view. http://backbonejs.org/#View-extend

Backbone.View.extend({
  tagName: "tr"
});
Simon Boudrias
  • 42,953
  • 16
  • 99
  • 134
0

Your template doesn't need to include the tr tags. tblView should have tagName set to tr.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • thanks, fixed my issue straight away:] mymy how have i been using backbone for last 1 year and not known this... – Tyler Evans Dec 19 '12 at 01:17