2015-10-19 24 views
1

我从路由器获取数据上下文,食谱没有显示在我的食谱page.I想问我在这里做错了什么?来自路由器和食谱的数据上下文不显示

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> 
+1

你在哪里订阅收藏?我们可以看到这些代码吗? – danSiebes

+0

这里是github链接https://github.com/soni1/foody @gdataDan – Waqar

+0

我想你需要阅读[http://docs.meteor.com/#/full/meteor_publish](http://docs.meteor .com /#/ full/meteor_publish“this”)。据我可以告诉你没有发布/订阅集合中的数据,因为你的集合是空的。 – danSiebes

回答

1

你的路线 弄乱。您似乎在以不解析的方式混合路由选项和渲染选项。另外,您的数据上下文没有配方作为字段。

也许以下是你想要的?

Router.route('/recipes', function() { 
    this.render('recipes', { 
     data: function() { 
      return { recipes: Recipes.find() }; 
     } 
    }); 
}, { 
    name:'recipes', 
}); 

我个人更喜欢将数据路由,而不是渲染调用和使用路由选项时可能:

Router.route('/recipes', { 
    name: 'recipes', 
    template: 'recipes', 
    data: function() { 
     return {recipes: Recipes.find()}; 
    } 
});