【发布时间】:2015-10-20 04:56:32
【问题描述】:
我正在从路由器获取数据上下文,但食谱没有显示在我的食谱页面上。我想问一下我在这里做错了什么?
collections.js
Recipes = new Mongo.Collection('recipes');
router.js
Router.route('/recipes', function () {
this.render('recipes',{
name:'recipes'
},
{
data: function(){
return Recipes.find();
}
});
});
recipes.html
<template name="recipes">
{{#each recipes}}
<div class="container" style="margin-top:10px;">
<div class="row form-group">
<div class=" col-md-4">
<div class="panel panel-default">
<div class="panel-image">
<img src="{{image}}" class="panel-image-preview" />
</div>
<div class="panel-body">
<h4>{{name}}</h4>
<p>{{description}}</p>
</div>
<div class="panel-footer text-center">
<a href="#"><span class="glyphicon glyphicon-open-file"></span></a>
<a href="#"><span class="glyphicon glyphicon-time" style="vertical-align:middle"></span><small> {{time}}</small></a>
<a href="#"><span class="glyphicon glyphicon-heart " style="vertical-align:middle"></span><small>15 </small></a>
<a href="#"><span class="glyphicon glyphicon-share"></span></a>
</div>
</div>
</div>
</div>
</div>
{{/each}}
</template>
【问题讨论】:
-
您在哪里订阅收藏?我们能看到那个代码吗?
-
这里是github链接github.com/soni1/foody@gdataDan
-
我认为你需要阅读http://docs.meteor.com/#/full/meteor_publish。据我所知,您没有发布/订阅集合中的数据,而且您的集合只是空的。
-
我还没有删除默认的自动发布和不安全的包,所以暂时不需要发布数据。
-
在您的食谱页面内部,Recipes.find().count() 是否返回大于 0 的数字?您的示例数据或插入数据的结构也是这样的:{recipes:{name:x,image:y},{name:x,image:y}} 等?
标签: meteor iron-router meteor-blaze