I am brand new at this Javascript/JSON/Handlebars thing, and I am having trouble getting a JSON object, with two nested levels, to work in a Handlebars template.
I hav
pdjota is right on. This answer is just to show how to use the each block helper if you wanted.
Like pdjota wisely pointed out, you are overwriting the elements of your object because they all have the same key i.e., "Chapter". So turn data
into an array of objects instead of an object of objects that have the same key.
If you do that, you can still pass data
into template()
. What you were missing was how to reference properties of objects used in the each block. That is done with this
. For example, if you are in the movies iterator, properties of the movies object are referenced like this: this.movieIDnum
, this.movieName
, etc.
Handlebars Demo