Calling function in mustache Javascript to process a list and generate a list

68 Views Asked by At

In mustache I know how to write a function with arguments but I want to process a list of data through a function. So, my JSON data from an API call is as follows:

result = [{email: ‘[email protected]’, score1: 2, score2: 3}, {email: ‘[email protected]’, score1: 5, score2: 3}, {email: ‘[email protected]’, score1: 2, score2: 0} ]

Now, I actually want to repeat an image in html for the number stated in score1 and score2. So, in html I want to have 2 images of stars and 3 images of flames for 1st entry. Similarly, for the consecutive elements in the list.

The other way would be to iterate though the list and then assign a variable to be [1,2] in mustache. But, I want to avoid iterating as there would be too many records.

Please help me. Thanks in advance.

0

There are 0 best solutions below