我知道我在做一些愚蠢的事情,但我的骨幹木偶應用程序給我的模板錯誤沒有任何意義。它似乎是在提取事件發生之前呈現單個項目。Backbone Marionette在抓取完成之前顯示
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g
};
MyApp = new Backbone.Marionette.Application();
MyApp.addRegions({
TagsRegion: "#tagsHolder"
});
MyApp.NoItemsView = Backbone.Marionette.ItemView.extend({
template: "#show-no-items-message-template"
});
MyApp.Tag = Backbone.Model.extend({
});
MyApp.TagCollection = Backbone.Collection.extend({
model: MyApp.Tag,
url: '/API/Tag'
});
MyApp.TagItemView = Backbone.Marionette.ItemView.extend({
template: "#tag-template",
tagName: 'li'
});
MyApp.TagCollectionView = Backbone.Marionette.CollectionView.extend({
itemView: MyApp.TagItemView,
emptyView: MyApp.NoItemsView,
tagName: 'ul'
});
MyApp.addInitializer(function(options){
var tagCollection = new MyApp.TagCollection({
});
var tagCollectionView = new MyApp.TagCollectionView({
collection: tagCollection
});
tagCollection.fetch();
MyApp.TagsRegion.show(tagCollectionView);
});
和我的HTML頁面
<div id="TagsDiv">
<h1>Tags</h1>
<div id="tagsHolder"></div>
</div>
<script type="text/template" id="show-no-items-message-template">
No items found.
</script>
<script type="text/template" id="tag-template">
{{ TagName }}
</script>
<script type="text/javascript" src="/Scripts/Views/Home/Upload.js"></script>
<script type="text/javascript">
$(document).ready(function() {
MyApp.start();
});
如果我從我的標籤模板中刪除小鬍子它顯示1:「變量名」,那麼當抓取完成它顯示了正確的號碼。
如果我把小鬍子早在我得到「標記名未定義」
我覺得我有倒退的我的模式之一。我太近了,看不到它。
感謝 馬克
如果你想創建一個帶有ID的模型,你如何解決這個問題? –
我不明白問題 –
我在這裏創建了一個單獨的問題:http://stackoverflow.com/questions/13567305/how-to-prevent-backbone-marionette-from-rendering-a-view-if-它的模型,處理不當,是 –