【发布时间】:2018-07-10 16:21:44
【问题描述】:
我有一个 handelbars 页面,根据 json 中的标题项目,它会显示不同的内容。
到目前为止,这是使用 helper if_wq
构建的例如 if title = test 这有效
我想要一种方法来扩展此功能以显示 if title = test 和 colors.href = /test
所以条件只有在两个条件都为真时才有效。
我的代码示例
{{#if_eq title 'test'}}
True
{{/if_eq}}
我的助手任务示例
handlebars.Handlebars.registerHelper('if_eq', function(a, b, opts) {
if (a === b) {
return opts.fn(this);
} else {
return opts.inverse(this);
}
});
我的 json 示例
"range-list-page": {
"ranges": [
{
"title": "test",
"colors": [
{
"color": "#fff",
"label": "White",
"bordered": true,
"href" : "/test"
},
{
"color": "#F3DCAE",
"label": "Cream",
"href" : "http://google.com"
},
{
"color": "#C5B7B0",
"label": "Cashmere",
"href" : "http://google.com"
},
{
"color": "#D0B193",
"label": "Larch",
"href" : "http://google.com"
}
]
【问题讨论】:
标签: html arrays json conditional handlebars.js