2016-09-07 53 views
0

我想我怎樣才能創建一個使用此車把方程式中使用嵌套操作Handlerbars像嵌套操作的把手

if(value == "a" || value == "b") 

在此先感謝

回答

1

創建助手(我用underscore.js爲simplicify):

eq.js

Handlebars.registerHelper('eq', function() { 
    var i, options, val1, vals; 
    val1 = arguments[0], vals = 3 <= arguments.length ? slice.call(arguments, 1, i = arguments.length - 1) : (i = 1, []), options = arguments[i++]; 
    return _.any(vals, function(val) { 
    return val1 === val; 
    }); 
}); 

eq.coffee

Handlebars.registerHelper 'eq', (val1, vals..., options) -> _.any vals, (val) -> val1 is val 

並用途:

{{eq value 'a' 'b'}}