I am trying to access the index of a loop, while displaying the elements of a Collection.
{{#attachments}}
<div>Returns the whole Attachment object: {{this}}</div>
<div>Is a property of the Attachment class: {{fileName}}</div>
{{/attachments}}
With {{this}}
I can access the whole object Attachment [id=24fileName=image002.jpg, hash=E+Rasjhdgsajh=, signed=false]
, which does not really help.
I understood that Mustache.js apparently supports indexes with {#index}
Stackoverflow question.
In Mustache.java something like that was proposed, but not implemented, because it would encourage poor separation between the template and the data. cf. Support for array item by index.
Sam Pullara suggested to use this workaround, which I unfortunately can't really make sense of.
I am now considering adding a field to my Attachment
class representing an index, but would like to know if there is another way to deal with this problem.
The Javadocs Mustache unfortunately, don't seam to exist yet.
Any help or suggestions are greatly appreciated.