2
我在車把頁上有兩種類型的值,需要比較第一個和第二個。 我可以打印頁面上寫的每個循環之前下面的代碼每個循環內的車把比較運算符
{{articledetails.content_writer_id}}
的價值。現在我想比較下面的值。但我無法得到articledetails.content_writer_id在以下代碼的範圍。
{{#each contentwriterdetails}}
{{#compare this.id "==" articledetails.content_writer_id }}
我已經註冊了通過使用此代碼比較幫手。
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);
}
});
及以上幫助程序工作正常,因爲我已經檢查過。
任何幫助,將不勝感激。
你試過'../ articledetails.content_writer_id'? – Jcl
太棒了!你可以發佈它作爲答案。 – Kishor
你在那裏... – Jcl