0

I have inserted this nested data in my minimongo

db.orders.insert({ 
    _id: ObjectId().str,
    name: "admin",
    status: "online",catalog : [{
        "objectid" : ObjectId().str,
        "message" : "sold",
        "status" : "open"
    }]
});

and i am trying to display it with this code

<template name="Listed">
    <div class="row">
        {{#each list}}
            <article class="post">
                <a href="{{pathFor route='edit'}}"><h3>{{_id}}</h3></a>
                <a href="{{pathFor route='edit'}}"><h3>{{name}}</h3></a>
                <br>
                <a href="{{pathFor route='create'}}"><h3>{{status}}</h3></a>
                <br>
                {{#each ../catalog}}
                    <a href="{{pathFor route='create'}}"><h3></h3></a>
                    <a href="{{pathFor route='create'}}"><h3>{{status}}</h3></a>
                {{/each}}
                <div class="well"></div>
                <br/>    
            </article>
            <br/><br/>
        {{/each}}
    </div>
</template>

but the nested data is not being displayed. How can i display the nested data?.

This is my data helper

/*****************************************************************************/
/* Listed: Helpers */
/*****************************************************************************/
Template.Listed.helpers({
    'list': function(){
        return Orders.find();
    }
});
Konrad Lindenbach
  • 4,911
  • 1
  • 26
  • 28
Le Qs
  • 785
  • 2
  • 9
  • 26

1 Answers1

2

you need to remove ../

<template name="Listed">
    <div class="row">
        {{#each list}}
            <article class="post">
                <a href="{{pathFor route='edit'}}"><h3>{{_id}}</h3></a>
                <a href="{{pathFor route='edit'}}"><h3>{{name}}</h3></a>
                <br>
                <a href="{{pathFor route='create'}}"><h3>{{status}}</h3></a>
                <br>
                {{#each catalog  }}
                    <a href="{{pathFor route='create'}}"><h3></h3></a>
                    <a href="{{pathFor route='create'}}"><h3>{{status}}</h3></a>
                {{/each}}
                <div class="well"></div>
                <br/>    
            </article>
            <br/><br/>
        {{/each}}
    </div>
</template>

```

Kishor
  • 2,659
  • 4
  • 16
  • 34
JBoulhous
  • 844
  • 7
  • 11
  • This is the nested object `{ "objectid" : ObjectId().str, "message" : "sold", "status" : "open" }` that i have. Is there a way i can access the name of the key and value of the nested object i.e i would to display the key "status" and the value "open". I can display the value of status by {{ status}} but how can i display the key. I say this because,at times,i wont know the keys offhead. – Le Qs Apr 04 '16 at 15:48
  • @LeQs try accessing the key of the object with `{{@index}}` – rdk1992 Apr 04 '16 at 15:56
  • @rdk1992 a small example will help. – Le Qs Apr 04 '16 at 15:57
  • @LeQs the example JBoulhous provided is good, you just mentioned you are missing the key: try `{{#each catalog}} Key: {{@index}} Status: {{status}} {{/each}} ` Just put {{@index}} where you want to display the key of the object. – rdk1992 Apr 04 '16 at 15:58
  • @rdk1992 Thanks for your input. To be a little bit more clear,the `catalog` object is all i have. I want to print out the key/value pairs under the `catalog` object. In the real app,i wont know the key/value pairs. – Le Qs Apr 04 '16 at 16:10
  • @LeQs oh I see, you won't know neither key/value pairs of the object. So for printing the keys use `{{@index}}` and for printing the values use `{{.}}`. Hope this works. – rdk1992 Apr 04 '16 at 16:15
  • @rdk1992 `{{@index}}` is only outputting 0,1,2,3.. and not any of the `{ "objectid" : ObjectId().str, "message" : "sold", "status" : "open" }` fields – Le Qs Apr 04 '16 at 16:19
  • @LeQs I see, then try registering a global helper where you iterate your catalog object and set the key/value to an array. Check here for example: http://stackoverflow.com/questions/15035363/meteor-and-handlebars-each-to-iterate-over-object – rdk1992 Apr 04 '16 at 16:22