javascript - Accessing nested data via Handlebars.js using 'this' as second property value -


i’m having trouble accessing nested data via handlebars. i've searched similar questions none of them involve using value of 'this' property name.

here's data:

var activity_groups = ["foo", "bar", "blargh"]; //this array generated dynamically , may have or of these elements  var hb_data = {     "activity_groups"   : activity_groups,     "img_alt" : {         "foo"       : "foo alt",         "bar"       : "bar alt",         "blargh"    : "blargh alt"     },     "img_src" : {         "foo"       : "foo src",         "bar"       : "bar src",         "blargh"    : "blargh src"     },     "title" : {         "foo"       : "foo title",         "bar"       : "bar title",         "blargh"    : "blargh title"     },     "desc" : {         "foo"       : "foo desc",         "bar"       : "bar desc",         "blargh"    : "blargh desc"     } } 

the template:

{{#each activity_groups}} <div data-type="{{this}}">     <img class="activity_group_selector_img" alt="{{../img_alt.this}}" src="{{../img_src.this}}" />     <span>{{../title.this}}</span>     <div class="activity_group_selector_description">{{../desc.this}}</div> </div> {{/each}} 

the problem these:

{{../img_alt.this}} {{../img_src.this}} {{../title.this}} {{../desc.this}} 

which throw uncaught error: invalid path

is there way use value of 'this' access nested data?

i’m open entirely different solutions, i’d know how using current model.

create helper:

handlebars.registerhelper('getproperty', function(context, key) {     return context[key]; }); 

example of usage:

{{getproperty ../img_alt this}} 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -