javascript 把手:将多个参数传递给 registerHelper 函数的最佳方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17870635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Handlebars : What is the best way to pass multiple parameters to a registerHelper function?
提问by dhruvpatel
I am using Handlebars to render data in a table.
我正在使用 Handlebars 在表格中呈现数据。
One of the data items needs processing, which takes a few parameters into account in order to provide outcome.
其中一个数据项需要处理,需要考虑几个参数才能提供结果。
The templated text example :
模板化文本示例:
{{getOutputByParameters param1=DataFieldName1 param2=DataFieldName2}}
And corresponding registerHelper would be written as:
相应的 registerHelper 将写为:
var __this = this;
Handlebars.registerHelper('getOutputByParameters', function(params){ __this.getOutputByParameters(params.hash.param1, params.hash.param2)})
I figured that handlebars would pass an array of these parameters, which I can access using hash property.
我认为车把会传递这些参数的数组,我可以使用 hash 属性访问这些参数。
But is that the only best way?
但这是唯一最好的方法吗?