在模板中显示Handlebars.js上下文 [英] Display Handlebars.js context in a template
本文介绍了在模板中显示Handlebars.js上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否在每个handlebar.js模板中传递了一个变量,该变量包含该模板可访问的所有上下文内容?
Is there a variable passed into every handlebar.js template that contains all the context content that is accessible by the template?
例如我正在创建一个模板,但是我不知道该模板可访问的所有上下文内容.我希望能够输入模板{{ debug }}
,handlebars.js会将所有上下文内容吐到HTML
e.g. I'm creating a template, but I don't know all the context content accessible by the template. I want to be able to type into the template {{ debug }}
and handlebars.js will spit out all the context content into the HTML
推荐答案
您可以使用以下代码遍历this
对象:
You can use the following code to iterate through this
object:
{{#each this}}
{{@key}}: {{this}}
{{/each}}
或通过@root
对象迭代的类似代码:
or a similar piece of code iterating through @root
object:
{{#each @root}}
{{@key}}: {{this}}
{{/each}}
这篇关于在模板中显示Handlebars.js上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文