javascript - Output Nested Handlebar helpers that exist in the data -


i coming against wall , not seeing how can loop on handlebar helpers found in provided data. adjusted jsfiddle illustrate i'm looking do. appreciated.

you see {{position.one}} in data equal string team lead can output without problem, when helper used inside {{person.jobtitle}}, outputs front end {{position.one}}.

is there way have output {{position.one}} in {{person.jobtitle}} output front end team lead?

here fiddle. taking look!

http://jsfiddle.net/z9u5jz7w/1/

re: @luciano-santos trying find way loop on regardless if expression standalone or data contains expression.

i found library extension (https://github.com/mateusmaso/handlebars.nested), seems work if expression directly in expression being evaluated ie {{jobtitle {{position.one}} }} instead of {{jobtitle}} containing {{position.one}} expression.

seems may need write evaluate if expression contains {{ , re-evaluate.

answer

ended writing custom helper this. helps else well. helper allows evaluation of nested expressions found in json or given dataset.

https://github.com/davidwickman/handlebars-helper-inception

in handlebars, expression cannot contain other expressions. you'd better prepare data before sending handlebars, did name:

var data = {      users: [ {          person: {             firstname: "garry",              lastname: "finch"         },         job: {             title: "front end",             position: "team lead"         },         twitter: "gazraa"      } ] }; 

this way, can create helper, did person's name, , concat both values.

handlebars.registerhelper('fulljob', function(job) {   return job.title + " " + job.position; }); 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -