Meteor.js Handlebars模板逻辑运算符 [英] Meteor.js Handlebars template logic operators
问题描述
从此页面,我插入到我的/client/helpers/handlebars.js文件中的这个句柄帮助器:
Handlebars.registerHelper('compare',function (lvalue,operator,rvalue,options){
var操作符,结果;
if(arguments.length< 3){
throw new Error( Handlerbars Helper'compare'needs 2 parameters);
}
if(options === undefined){
options = rvalue;
rvalue = operator;
operator ====;
}
operators = {
'==':function(l,r){return l == r;} ,
'===':function(l,r){return l === r;},
'!=':function(l,r){return l!= r;} ,
'!==':function(l,r){return l!== r;},
'<':function(l,r){return l< r;} ,
'>':function(l,r){return l> r;},
'< =':function(l,r){return l <= r; },
'> =':function(l,r){return 1> = r; },
'typeof':function(l,r){return typeof l == r; }
};
if(!operators [operator]){
throw new Error(Handlerbars Helper'compare'不知道操作符+操作符);
}
result = operators [operator](lvalue,rvalue);
if(result){
return options.fn(this);
} else {
return options.inverse(this);
}
});
以及模板: 我也试过这个: 但这没有帮助。 试试 From this page, I inserted to my /client/helpers/handlebars.js file this handlebars helper: And to the template: And in console I always see: Exception from Deps recompute: Error: Handlerbars Helper 'compare' needs 2 parameters I tried this as well: But this did not help. Try
这篇关于Meteor.js Handlebars模板逻辑运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<$ p $ {{#compareTestTest}}
===的默认比较
{{/比较}}
$ c在控制台中,我总是看到:Deps的异常重新计算:Error:Handlerbars Helper'compare'需要2个参数$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b
{{#compareTest==测试}}
{{#compareTest ===}}
Handlebars.registerHelper('compare', function (lvalue, operator, rvalue, options) {
var operators, result;
if (arguments.length < 3) {
throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
}
if (options === undefined) {
options = rvalue;
rvalue = operator;
operator = "===";
}
operators = {
'==': function (l, r) { return l == r; },
'===': function (l, r) { return l === r; },
'!=': function (l, r) { return l != r; },
'!==': function (l, r) { return l !== r; },
'<': function (l, r) { return l < r; },
'>': function (l, r) { return l > r; },
'<=': function (l, r) { return l <= r; },
'>=': function (l, r) { return l >= r; },
'typeof': function (l, r) { return typeof l == r; }
};
if (!operators[operator]) {
throw new Error("Handlerbars Helper 'compare' doesn't know the operator " + operator);
}
result = operators[operator](lvalue, rvalue);
if (result) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
{{#compare "Test" "Test"}}
Default comparison of "==="
{{/compare}}
{{#compare "Test" "==" "Test"}}
{{#compare "Test" "Test" operator="=="}}