骨干木偶显示之前获取完成 [英] Backbone Marionette Displaying before fetch complete
问题描述
我知道我在做一些愚蠢的事,但我的骨干提线木偶的应用程序是给我的模板的错误,没有任何意义。这似乎是渲染一个项目之前,获取事件发生。
I know i am doing something stupid but my backbone marionette app is giving me template errors that don't make sense. It appears to be rendering a single item before the fetch event happens.
_.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:变量名,那么当抓取完成它显示正确的号码
If I remove the mustaches from my tag-template it displays 1: " TagName " then when the fetch completes it shows the right number.
如果我把胡子早在我得到标记名没有定义
if i put the mustaches back in i get "TagName is not defined"
我觉得我有倒退的我的模式之一。我只是太靠近看看吧。
I feel that i have one of my patterns backwards. I am just too close to see it.
谢谢
马可福音
Thanks -Mark
推荐答案
问题是这条线在你的初始化
The problem is this line in your initializer
var tagCollection = new MyApp.TagCollection({
});
当你传递一个空对象文本到一个Backbone.Collection构造,骨干创建集合在一个空的模型。为了解决这个问题,只是删除对象字面:
When you pass an empty object literal in to a Backbone.Collection constructor, Backbone creates an empty model in the collection. To fix this, just remove the object literal:
VAR tagCollection =新MyApp.TagCollection()
和它不会有它的空项目了。
and it won't have the empty item in it anymore.
这篇关于骨干木偶显示之前获取完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!