AFAIKoptions
将永远是最后一个论点。助手并没有完全记录或指定得很好,但我认为假设最后一个参数总是options
.
也就是说,您可以使用 splat 参数在 CoffeeScript 中更简洁地执行此操作:
Handlebars.registerHelper "ifAny", (conditions..., options)->
for condition in conditions
return options.inverse @ if !condition
options.fn @
也许:
Handlebars.registerHelper "ifAny", (conditions..., options)->
for condition in conditions
return options.inverse @ unless condition
options.fn @
甚至可能:
Handlebars.registerHelper "ifAny", (conditions..., options)->
return options.inverse @ for condition in conditions when !condition
options.fn @
Kamil Szot指出您的助手名称 ( ifAny
) 与您使用的逻辑不匹配。您的逻辑ifAny
真的应该在一个名为的助手中ifAll
,并且ifAny
应该是以下之一:
Handlebars.registerHelper 'ifAny', (conditions..., options)->
for condition in conditions
return options.fn @ if condition
options.inverse @
Handlebars.registerHelper 'ifAny', (conditions..., options)->
return options.fn @ for condition in conditions when condition
options.inverse @