我希望创建一个全局计数器,每次使用它时,它都将被替换为下一个值,例如{计数器},如果我在模板中使用如下所示
然后将呈现为
这能通过handlebarJS实现吗?
发布于 2018-04-23 15:30:22
您可以使用HandlebarsHelper来实现这一点。
var temp = 1;
Handlebars.registerHelper('Counter', function() {
return temp++;
});你的车把模板是,
This is line {{Counter}}
This is line {{Counter}}
This is line {{Counter}}
This is line {{Counter}}哪个输出
This is line 1
This is line 2
This is line 3
This is line 4使用- http://tryhandlebarsjs.com/测试
希望这能有所帮助。
https://stackoverflow.com/questions/49945310
复制相似问题