Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

82
Views
In handlebars, how to know if I'm at the last occurence of the parent array

I'm struggling on a little problem of mine in a handlebars project. I am working with a set of nested arrays like so:

[
   [
      [
         {Object: "Object1"},
         {Object: "Object2"}
      ],
      [
         {Object: "Object3"},
         {Object: "Object4"}
      ]
   ],
   [
      [
         {Object: "Object5"},
         {Object: "Object6"}
      ],
      [
         {Object: "Object7"},
         {Object: "Object8"}
      ]
   ],
   [
      [
         {Object: "Object5"},
         {Object: "Object6"}
      ],
      [
         {Object: "Object7"},
         {Object: "Object8"}
      ]
   ]
]

I know i can use the @first and @last booleans to know if I'm at the last element of the currently iterating array.

{{#each foo}}
    <div class='{{#if @first}}first foo{{/if}}
                {{#if @last}} last foo{{/if}}'>
      {{@key}} - {{@index}}
    </div>
{{/each}}

but what if I want to know whether or not I'm on the last element of a parrent array?

{{#each fooParent}}
   {{#each foo}}
       <div class='{{#if @first}}first foo not fooparent{{/if}}
                   {{#if @last}} last foo not fooparent{{/if}}'> <!-- How can I know here 
                                                                      that I am on the 
                                                                      last item of the 
                                                                     fooParent array? --> 
         {{@key}} - {{@index}}
       </div>
   {{/each}}
{{/each}}

anyone know how to "get back" in the arrays to know, for example, if I'm on the last element of parent array?

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.