Looping through a multidimensional array in Handlebars.js

I have the server passing back this JSON and I'm not sure how to loop through a 2-dimensional array in Handlebars.

"userSurvey":[[1],[2],[3]]

I know to use {{#each userSurvey}} but then how would I go about do the arrays inside the usersurvey object?

Answers


You'd have to loop 2 times:

{{#each userSurvey}}
  {{#each this}}
    {{ this }}
  {{/each}}
{{/each}}

In this particular case if you want to render just "123" you can do this:

{{#each userSurvey}}
    {{this.[0]}}
{{/each}}

Or even simpler, because arrays automatiaclly transform to strings:

{{#each userSurvey}}
    {{this}}
{{/each}}

    {{#each Arr}}
        {{#each this}}
            <label>{{this.[0]}}</label> {{this.[1]}}<br>
        {{/each}}
    {{/each}}

Here is my simple example to loop array of my arrays :)


Need Your Help

Get specific object by id from array of objects in AngularJS

javascript arrays angularjs json object

I have a JSON file containing some data I d like to access on my AngularJS website. Now what I want is to get only one object from the array. So I d like for example Item with id 1.

Tracking report usage

reporting-services reportingservices-2005

Is there an easy way to track who is running a given report in SSRS 2005, and at what time they are running that report? We have about 80 reports in our SSRS implementation, and are trying to see if