我是Marionette的新人。我开始了解木偶复合视图。我不知道我是错的还是写的。Backbone.Marionette - 如何使用CompositeView在模板中添加静态HTML内容?
我的问题是,我如何保持我的模板上的一些静态HTML内容?
我复合视图模板:
<script type="text/template" id="angry_cats-template">
<div><a href="#logout">Click to logout</a></div> // i would like to add some static html here.
<thead>
<tr class='header'><th>Name</th></tr>
</thead>
<tbody></tbody>
</script>
<script type="text/template" id="angry_cat-template">
<td><%= name %></td>
</script>
而且我渲染这样的:
myApp = new Backbone.Marionette.Application();
myApp.addRegions({
mainRegion:"#content"
});
AngryCat = Backbone.Model.extend({});
AngryCats = Backbone.Collection.extend({
model:AngryCat
});
AngryCatView = Backbone.Marionette.ItemView.extend({
template:"#angry_cat-template",
tagName:'tr',
className:'angry_cat'
});
AngryCatsView = Backbone.Marionette.CompositeView.extend({
tagName:"table", //how to avoid my logout should not append with table?
id:"angry_cats",
className: "table-striped table-bordered",
template: "#angry_cats-template",
itemView: AngryCatView,
appendHtml: function(collectionView, itemView){
collectionView.$("tbody").append(itemView.el);
}
});
myApp.addInitializer(function(options){
var cats = new AngryCats([
{ name: 'Wet Cat' },
{ name: 'Bitey Cat' },
{ name: 'Surprised Cat' }
]);
var angryCatsView = new AngryCatsView({
collection: cats
});
myApp.mainRegion.show(angryCatsView);
});
$(document).ready(function(){
myApp.start();
});
任何一个帮助我吗?
谢谢Seabiscuit。你能否编辑更新版本的答案? –