流星-不填充{{each}},即使控制台说数据在那里
Meteor - not populating {{each}} even when console says data is there
根据下面的代码,为什么我没有得到Categories
列表的填充,即使浏览器控制台显示6时,我输入Categories.find().count()
?
我做错了什么?这是我在GitHub上的仓库。
categories.js:
Categories = new Mongo.Collection('categories');
if (Meteor.isServer) {
Categories.allow({
insert: function(userId, doc) {
return true;
},
update: function(userId, doc, fieldNames, modifier) {
return true;
},
remove: function(userId, doc) {
return true;
}
});
}
home_controller.js:
HomeController = RouteController.extend({
subscriptions: function() {
this.subscribe('categories');
this.subscribe('photos');
},
data: function () {
console.log(this.params.name);
Session.set('category', this.params.name);
},
action: function () {
this.render('MasterLayout', {});
}
}
list_categories.html:
<template name="ListCategories">
<ul>
{{#each Categories}}
<li id="categories"><a class="btn btn-default" href="/{{name}}">{{name}}</a></li>
{{/each}}
</ul>
</template>
list_categories.js:
Template.ListCategories.helpers({
Categories: function() {
return Categories.find();
}
});
list_photos.html:
<template name="ListPhotos">
<div id='photos'>
<div class='page-header'>
<h1>
<small>
{{#if catnotselected}}
Photos
{{else}}
{{category}} Photos
{{/if}}
</small>
</h1>
</div>
<div id='mainContent'>
{{#each photolist}} {{>photo}} {{else}} {{#if catnotselected}}
<div class='page-header'>
<h1><small>Select a category.</small></h1></div>
{{else}}
<div class='page-header'>
<h1><small>No photos in this category.</small></h1></div>
{{/if}} {{/each}}
</div>
</div>
</template>
list_photos.js:
Template.ListPhotos.helpers({
catnotselected: function() {
return Session.equals('category', null);
},
category: function() {
return Session.get('category');
}
});
master_layout.html:
<template name="MasterLayout">
<div class="navbar">
<div class="container">
<div class="navbar-inner">
<a class="brand btn" href="/"><img style="height: 40px; width: 135px;" src="img/logo.png" />
<p>Photos</p>
</a>
<div id="login-button" class="btn btn-default pull-right">
{{> loginButtons}}
</div>
</div>
</div>
</div>
<div class='container-fluid'>
<div class='row'>
<div class='col-xs-12 text-center'>
{{> yield 'categories'}}
</div>
<div class='col-xs-10 col-xs-offset-1 text-center'>
{{> yield 'photos'}}
</div>
</div>
</div>
</template>
master_layout.js:
Template.MasterLayout.onCreated(function() {
Session.set('category', null);
});
photos.js:
Photos = new Mongo.Collection('photos');
if (Meteor.isServer) {
Photos.allow({
insert: function(userId, doc) {
return true;
},
update: function(userId, doc, fieldNames, modifier) {
return true;
},
remove: function(userId, doc) {
return true;
}
});
}
routes.js:
Router.configure({
layoutTemplate: 'MasterLayout',
loadingTemplate: 'Loading',
notFoundTemplate: 'NotFound',
yieldTemplates: {
'photos': {
to: 'ListPhotos'
},
'categories': {
to: 'ListCategories'
}
}
});
Router.route('/', {
name: 'home',
controller: 'HomeController',
action: 'action',
where: 'client'
});
Router.route('/:name', {
name: 'photos',
controller: 'HomeController',
action: 'action',
where: 'client'
});
正如预期的那样,ListPhotos
和ListCategories
模板渲染失败。这就是为什么DOM中没有相应的元素,即使您可以通过控制台访问Photos
和Categories
集合的文档。
显然,由于铁路由器问题,在全局路由器配置中使用yieldRegions
将失败,这需要在路由的操作中调用this.render()
。
routes.js:
Router.configure({
layoutTemplate: 'MasterLayout',
loadingTemplate: 'Loading',
notFoundTemplate: 'NotFound',
yieldRegions: {
//each yield going to different templates
'ListPhotos': {
to: 'photos'
},
'ListCategories': {
to: 'categories'
}
}
});
Router.route('/', {
name: 'home',
controller: 'HomeController',
action: function () {
this.render();
},
where: 'client'
});
Router.route('/:name', {
name: 'photos',
controller: 'HomeController',
action: function () {
this.render();
},
where: 'client'
});
相关文章:
- 将数据传递到自定义控制台
- 如何使用谷歌地理编码将地址转换为坐标后控制台日志数据
- 如果从浏览器控制台提交,Knockoutjs不会保存数据
- 如何在控制台.log中打印 JSON 数据
- 将数据从 Web 浏览器控制台导出到剪贴板或文本文件
- 为什么我的 ajax 调用不将数据存储在数据库中?没有 PHP 或控制台错误
- 使用浏览器控制台发送 ajax 数据
- 从控制台显示的数据属性值,但不使用脚本显示
- 在我的visual studio应用程序页面中显示正在运行的控制台程序数据输出
- 从输入中获取数据,并在提交按钮上单击控制台日志记录数据
- 如何在控制台的多行中更新数据
- 如何从浏览器控制台停止数据发布
- 如何在Ui中显示数据,如果我在控制台获得数据在angular js
- 流星-不填充{{each}},即使控制台说数据在那里
- 显示数组数据,如控制台样式["1","2","3"]
- 我有这个数据读取到我的控制台.我想显示"exampleHeader"和“;exampleBody&q
- 如何将mysql数据管道传输到浏览器窗口,而不是Nodejs中的控制台
- 如何设置控制台数据
- 将node.js服务器接收到的数据打印到控制台
- 对本地 JSON 文件发出 XMLHttpRequest 以控制台日志数据