我正在尝试使用 CompositeView 和 ItemView 呈现引导导航列表。我需要生成的 html 类似于
<ul class="nav nav-list">
<li class="nav-header">List header</li>
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Library</a></li>
...
</ul>
为此,我有 3 个主干视图 -
<script type="text/html" id="vw-search-facets">
<h4>Filter By</h4>
<ul class="nav nav-list">
</ul>
</script>
<script type="text/html" id="vw-search-facet-group">
<li class="nav-header"><%= name %></li>
</script>
<script type="text/html" id="vw-search-facet">
<a href="#" id="<%= value %>"><%= name %> (<%= count %>)</a>
</script>
vw-search-facets 和 vw-search-facet-group 是 CompositeViews,vw-search-facet 是一个 ItemView。
但是,当它被渲染时,我会在 vw-search-facet-group 视图周围获得额外的 div
<ul class="nav nav-list">
<div>
<li class="nav-header">City</li>
<li><a href="#" id="Athens">Athens (9)</a></li>
<li><a href="#" id="Jackson">Jackson (2)</a></li>
</div>
</ul>
我可以理解这是因为 vw-search-facet-group 视图需要一个容器来渲染,因此默认情况下会创建一个 div,但这是不可取的。
如何更改它以删除那些额外的 div?
谢谢
更新视图定义
Reservations.SearchFacetView = Marionette.ItemView.extend({
model: Reservations.SearchFacet,
template: '#vw-search-facet',
tagName: 'li'
});
Reservations.SearchFacetGroupView = Marionette.CompositeView.extend({
template: "#vw-search-facet-group",
itemView: Reservations.SearchFacetView
});
Reservations.SearchFacetsListView = Marionette.CompositeView.extend({
itemView: Reservations.SearchFacetGroupView,
itemViewContainer: "ul.nav-list",
template: "#vw-search-facets"
});