I want to use the below helper
{{compare model.someCount 0 operator = ">"}}
How can I use it? I am getting error "Assertion Failed: Helpers may not be used in the block form, for example {{#my-helper}}{{/my-helper}}. Please use a component, or alternatively use the helper in combination with a built-in Ember helper, for example {{#if (my-helper)}}{{/if}}."
My helper looks as below;
import Ember from 'ember';
export function compare(lvalue, rvalue, options) {
if (arguments.length < 3)
throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
operator = options.hash.operator || "==";
var 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;
},
'typeof': function (l, r) {
return typeof l == r;
}
}
if (!operators[operator])
throw new Error("Handlerbars Helper 'compare' doesn't know the operator " + operator);
var result = operators[operator](lvalue, rvalue);
if (result) {
return options.fn(this);
} else {
return options.inverse(this);
}
}
export default Ember.Helper.helper(compare);
Aucun commentaire:
Enregistrer un commentaire