在 mustache 中,我知道如何编写带参数的函数,但我想通过函数处理数据列表。因此,来自 API 调用的 JSON 数据如下:
result = [{email: ‘xyz@test.com’, score1: 2, score2: 3},
{email: ‘abc@test.com’, score1: 5, score2: 3},
{email: ‘dummy@test.com’, score1: 2, score2: 0}
]
现在,我实际上想在 html 中为 score1 和 score2 中所述的数字重复一个图像。所以,在 html 中,我想要 2 张星星的图片和 3 张火焰的图片作为第一个条目。同样,对于列表中的连续元素。
另一种方法是遍历列表,然后在 mustache 中将变量分配为 [1,2]。但是,我想避免迭代,因为会有太多记录。
请帮我。提前致谢。