Backbone.js 提取完成前的主干木偶显示
我知道我在做一些愚蠢的事情,但我的主干木偶应用程序给了我一些毫无意义的模板错误。它似乎在fetch事件发生之前呈现单个项Backbone.js 提取完成前的主干木偶显示,backbone.js,marionette,Backbone.js,Marionette,我知道我在做一些愚蠢的事情,但我的主干木偶应用程序给了我一些毫无意义的模板错误。它似乎在fetch事件发生之前呈现单个项 _.templateSettings = { interpolate: /\{\{(.+?)\}\}/g }; MyApp = new Backbone.Marionette.Application(); MyApp.addRegions({ TagsRegion: "#tagsHolder" }); MyApp.NoItemsView = Back
_.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();
});
标签
没有找到任何项目。
{{标记名}}
$(文档).ready(函数(){
MyApp.start();
});
如果我从标记模板中删除胡须,它会显示1:“标记名”,然后在提取完成时,它会显示正确的数字
如果我把胡子放回我得到“标记名未定义”
我觉得我有一个模式是反向的。我太近了,看不见它
谢谢
-标记尝试:
tagCollection.fetch({ wait: true });
修改了模型,使其具有我想要模板的任何内容的默认值。感觉很糟糕,但它给了我一个有效的应用程序
MyApp.Tag = Backbone.Model.extend({
defaults :
{
TagName : 'None'
}
});
问题是您的初始值设定项中的这一行
var tagCollection = new MyApp.TagCollection({
});
当您将空对象文本传递给主干.Collection构造函数时,主干会在集合中创建一个空模型。要解决此问题,只需删除对象文字:
var tagCollection=new MyApp.tagCollection()
它不再有空项了。我也这样做了。。。如果你想创建一个带有id的模型,你会如何解决这个问题?我不理解这个问题我在这里创建了一个单独的问题: