dhr*_*tel 7 javascript template-engine handlebars.js
我正在使用Handlebars在表格中呈现数据.
其中一个数据项需要处理,其中考虑了一些参数以便提供结果.
模板文本示例:
{{getOutputByParameters param1=DataFieldName1 param2=DataFieldName2}}
Run Code Online (Sandbox Code Playgroud)
相应的registerHelper将被写为:
var __this = this;
Handlebars.registerHelper('getOutputByParameters', function(params){ __this.getOutputByParameters(params.hash.param1, params.hash.param2)})
Run Code Online (Sandbox Code Playgroud)
我认为把手会传递这些参数的数组,我可以使用hash属性访问它们.
但这是唯一最好的方式吗?
use*_*r10 16
不.根据他们的文档,您可以通过多种方式执行此操作.我会这样做的.
{{getOutputByParameters param1 param2}}
Handlebars.registerHelper('getOutputByParameters', function(param1, param2){
//do your stuff here.
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12356 次 |
| 最近记录: |