Search code examples
meteorhandlebars.jsmeteor-blaze

Meteor Blaze display array


I have collections like this:

enter image description here

I want to iterate over object.questions.teema for example.

I have helper:

Template.game.helpers({
    theGame: function() {
        var theGame = Game.findOne({_id:"LhQmaZKW8eJNenyX9"})
        console.log(theGame)
        return theGame
    }
});

and template:

<template name="game">

{{#with theGame}}
  {{#each theGame.questions}}
    {{teema}}
  {{/each}}
{{/with}}
</template>

But it doesnt work, what is wrong with the template?


Solution

  • '#each theGame.questions' Will not work inside the #with, because you can access the 'theGame' object directly.

    The point is when you try to get theGame object inside the #with it will return you undefined, because 'theGame' object does not have theGame property, Which you want to access inside #with block.

    <template name="game">
      {{#with theGame}}
        {{#each questions}}
           //Thie #each because you have nested array. As I can see in your console log.
           {{#each this}}
             {{teema}}
           {{/each}}
        {{/each}}
      {{/with}}
    </template>