把手:使用javascript变量进行索引 [英] Handlebars: using a javascript variable for index
本文介绍了把手:使用javascript变量进行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我希望能够做这样的事情:
So I want to be able to do something like this:
"{{tickets." + index + ".comments.0.account}}"
我希望能够使用javascript变量指定要从中获取数据的数组的索引.目前,这段代码给我一个错误,提示:
I want to be able to specify the index of the array that I am trying to get data from with a javascript variable. Currently this code gives me an error which says:
Expecting 'ID', got 'STRING'
如果有区别的话,我实际上是在Node.js上使用Express-Handlebars.
I am actually using express-handlebars with Node.js if this makes a difference.
推荐答案
创建助手:
Handlebars.registerHelper('getTicketAccount', function(context, i) {
// Error handling ommitted for brevity
return context[i].comments[0].account;
});
要使用:
{{getTicketAccount tickets index}}
这篇关于把手:使用javascript变量进行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文