1

I'm in the midst of learning meteorJS, so kindly forgive my ignorance at the moment.

I have a tasks collection at the back end MongoDB which contains something like this:

{
    "name": Something",
    "Address": {
        "Building": A,
        "Street": B,
        "Locality": C
        }
}

My HTML page that contains the template looks like this:

{{#each tasks}}

        {{> task}}

  {{/each}}

<template name="task">

  <li>{{Name}}</li>
<li>{{Address}}</li>
</task>

The problem I'm facing is that the Name gets rendered fine. However, the address seems to appear as [object Object]. I'm sure that i've messed up the way I iterate over the address field. Could someone help me with that?

Kris van der Mast
  • 16,343
  • 8
  • 39
  • 61
blueren
  • 2,730
  • 4
  • 30
  • 47

1 Answers1

2

You use either the dot notation or the square bracket notation to access the fields in an embedded document:

Dot notation:

<template name="task">
    <li>{{Name}}</li>
    <li>Address
        <ul>
            <li>Building - {{Address.Building}}</li>
            <li>Street - {{Address.Street}}</li>
            <li>Locality - {{Address.Locality}}</li>
        </ul>
    </li>   
</template>

Square bracket notation:

<template name="task">
    <li>{{Name}}</li>
    <li>Address
        <ul>
            <li>Building - {{Address["Building"]}}</li>
            <li>Street - {{Address["Street"]}}</li>
            <li>Locality - {{Address["Locality"]}}</li>
        </ul>
    </li>   
</template>
chridam
  • 100,957
  • 23
  • 236
  • 235
  • 1
    Thank you Chridam! Looks like I had also dome some errors at while persisting in the DB. I got it working now, after redoing from the beginning. – blueren Apr 26 '16 at 04:57