在助手的帮助下将表达式与车把中的键进行比较
Compare an expression with a key in handlebars with the help of a helper
我有一个定义为
的助手
'ifCond': function(v1, v2, options) {
if(v1 === v2) {
return options.fn(this);
}
return options.inverse(this);
}
}
现在,在 v1 和 v2 的位置,我有一个名为 {{index}} 的表达式和来自 {{each}} 的 {{@key}}。我想将它们等同起来..
当我在 hbs 中使用 helper 时,
{{#ifCond {{index}} {{@key}} }}
<p> Hello </p>
{{else}}
<p> Not Hello </p>
{{/ifCond}}
我收到这个错误
Expecting 'CLOSE_RAW_BLOCK', 'CLOSE', 'CLOSE_UNESCAPED', 'OPEN_SEXPR', 'CLOSE_SEXPR', 'ID', 'OPEN_BLOCK_PARAMS', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', 'SEP', got 'OPEN'enter code here
我该如何解决这个问题?
您不能在没有 {{}} 的情况下在助手调用 use index 或 @key 中使用大括号。
{{#ifCond index @key }}
此外,由于您没有使用 @index,我想您正在使用这样的 each 语句:
{{#each elements as |index| }}
我有一个定义为
的助手'ifCond': function(v1, v2, options) {
if(v1 === v2) {
return options.fn(this);
}
return options.inverse(this);
}
}
现在,在 v1 和 v2 的位置,我有一个名为 {{index}} 的表达式和来自 {{each}} 的 {{@key}}。我想将它们等同起来..
当我在 hbs 中使用 helper 时,
{{#ifCond {{index}} {{@key}} }}
<p> Hello </p>
{{else}}
<p> Not Hello </p>
{{/ifCond}}
我收到这个错误
Expecting 'CLOSE_RAW_BLOCK', 'CLOSE', 'CLOSE_UNESCAPED', 'OPEN_SEXPR', 'CLOSE_SEXPR', 'ID', 'OPEN_BLOCK_PARAMS', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', 'SEP', got 'OPEN'enter code here
我该如何解决这个问题?
您不能在没有 {{}} 的情况下在助手调用 use index 或 @key 中使用大括号。
{{#ifCond index @key }}
此外,由于您没有使用 @index,我想您正在使用这样的 each 语句:
{{#each elements as |index| }}