0

Here is the JSON:

{ 
"_id" : ObjectId("59c3edd10e2a6f083e858036"), 
"email" : "[email protected]", 
"username" : "aa", 
"password" : "$2a$10$WcUgbqFjsx.0BwkdEyDNP.R84vz1d7faaL8K0ORcIoBOXOAHxCS3.", 
"words" : [
    {
        "Name" : "xyz"
    }
], 
"title" : [

], 
"__v" : NumberInt(0), 
"name" : "obbk"
}

Here is my code for displaying data inside words

{{#users}}
    {{#words}}
        <h3>{{this.Name}}</h3>
    {{/words}}
{{/users}}

But it did not work.

so I wonder how to fix this, how to display Name inside of words, using handlebars as a template in nodejs to get data from an array inside of a JSON in MongoDB database.

1 Answer 1

2

Use:

{{#users}}
    {{#words}}
        <h3>{{Name}}</h3>
    {{/words}}
{{/users}}

Notice, that in an outer loop (through users) you already access words property without using this keyword, so keep up to that logic inside the inner loop (through words).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.