handlebars.js - Handlebars array access with dynamic index -


how can access array element inside handlebars template using variable instead of hardcoded value? need like:

{{#each condition in conditions}}     {{app.ops.[condition.op].name}} {{/each}} 

at moment doesn't give me parse error on runtime doesn't return me nothing. if this:

{{app.ops.[1].name}} 

it works it's not i'm looking for

related my answer on question


you can use the built-in lookup helper:

the lookup helper allows dynamic parameter resolution using handlebars variables. useful resolving values array indexes.

using lookup, example written as

{{#each condition in conditions}}     {{#with (lookup ../app.ops condition.op)}}         {{name}}     {{/with}} {{/each}} 

(note without knowledge of structure of data, i'm making assumption location of app.ops.)


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -