Reputation: 385
Have an array nested inside another array.
const data = [
id: 1,
plan_name: foo,
description: foo bar,
test: [{
id: 44,
activity_name: bar,
comment: var
},
{
id: 45,
activity_name: var,
comment: bar
}],
userId: 3
];
Printing data in a view template using:
{{#each data}}
<p>{{plan_name}}</p>
<p>{{test}}</p>
{{/each}}
The output is:
p1
[object Object],[object Object]
p2
[object Object],[object Object],[object Object]
p3
[object Object],[object Object]
How can I access the objects in the nested array using handlebars so that for every instance in the data array all items in the test array are printed?
Upvotes: 0
Views: 3202
Reputation: 727
Try this:
{{#each data}}
<p>{{plan_name}}</p>>
{{#each test}}
{{activity_name}}
{{comment}}
{{/each}}
{{/each}}
Upvotes: 1
Reputation: 13416
You can use the #with
handlebar to access the object
{{#each data}}
<p>{{plan_name}}</p>>
{{#with test}}
{{activity_name}}
{{comment}}
{{/with}}
{{/each}}
Upvotes: 1