javascript - access array of objects inside template -


i make 1 collection recipes , define schema , have 1 array of objects ingredients in schema , want access array of objects in template unable show them can please guide me how it?

collections.js

  recipes = new mongo.collection('recipes');     recipes.attachschema(new simpleschema({         name: {             type: string,             label: "recipe name",             max: 100         },              ingredients: {                 type: [object],                 mincount: 1             },          "ingredients.$.name": {         type: string             },         "ingredients.$.amount": {         type: string         },         description: {             type: string,             label: "how prepare ",         },         time: {             type: number,             label: "time (minutes)",         },         image: {             type: string,              autoform: {                 affieldinput: {                     type: "cfs-file",                     collection: 'recipesimages',                     label: 'recipe picture'                 }             }         }     })); 

router.js

router.route('/show_recipe/:_id', {     name: 'show_recipe',     template: 'show_recipe',     data: function() {         return recipes.findone(this.params._id);     } }); 

show_recipe.html

<template name="show_recipe">     <div class="container">         <div class="row">              <div class="col-md-8">                  {{#with fs.getfile "recipesimages" image}}                     <img class="img-responsive mt" src="{{url}}"/>                 {{/with}}             </div>             <div class="col-md-4" >                 <ul class="list-group">                      <h3> ingredients</h3>                         <li class="list-group-item">{{ingredients.name}} - {{ingredients.amount}}</li>                 </ul>              </div>          </div>         <div class="row">             <div class="col-md-8">                 <h4>{{name}}</h4>                 <p> {{description}}</p>             </div>         </div>     </div> </template> 

you're missing {{#each}} iterate on ingredients array. using set data context 1 element of array , can access keys directly:

<h3> ingredients</h3> {{#each ingredients}}   <li class="list-group-item">{{name}} -  {{amount}}</li> {{/each}} 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -