【发布时间】:2011-11-14 10:15:03
【问题描述】:
我正在使用来自主干.js 的 underscore.js 的模板功能,我在我的页面中定义了以下模板,如下所示:
<script type="text/template" id="businessunit_template">
<tr data-uid="{{Uid}}">
<td class="first"><span>{{Name}}</span></td>
<td class="{{StatusClass}} tac">{{OverallScore}}%</td>
<td>
<a class="impactanalysis individualBu" href="#"> </a>
</td>
</tr>
</script>
我将 trs 附加到下表的 tbody 元素:
<table class="listing">
<thead>
<tr>
<th class="first">Business Units</th>
<th>BCMS<br />Status</th>
<th>View</th>
</tr>
</thead>
<tbody id="reportBusinessUnits"></tbody>
</table>
呈现 tr 的个人主干视图如下所示:
class ReportBusinessUnitView extends MIBaseView
initialize: (options) ->
@vent = options.vent
@template = _.template($('#businessunit_template').html())
events:
"click .individualBu": "showBusinessUnitDetail"
showBusinessUnitDetail: (e) =>
e.preventDefault()
self = @
@vent.trigger('management:showbusinessunitdeail', @model)
render: =>
$(@el).html(@template(@model.toJSON()))
@
问题是,渲染的输出在 tr 周围有一个 div,我不知道它来自哪里:
<div>
<tr data-uid="a5e3c218-1ca4-4806-b27e-24a25ed83ab6">
<td class="first"><span>Central Networks</span></td>
<td class="red tac">4%</td>
<td>
<a class="impactanalysis individualBu" href="#"> </a>
</td>
</tr>
</div>
我只是看不出我做错了什么。有人知道这可能来自哪里吗?
【问题讨论】:
-
您可能想查看stackoverflow.com/a/10329499/441108,这将允许您在模板中保留
<tr>;这样可以更轻松地在其上设置data-uid属性等内容。