Javascript 传递处理程序后,把手上下文丢失
我确信这是非常基本的,但我无法在Javascript 传递处理程序后,把手上下文丢失,javascript,handlebars.js,Javascript,Handlebars.js,我确信这是非常基本的,但我无法在{{{if_eq}}中使用../model。我甚至尝试使用.././model,这指向model的一个子项。\u revs\u info {{#each model._revs_info}} {{debug ../model}} {{#if_eq status compare="available"}} {{debug ../model}} <a href="#list/
{{{if_eq}}
中使用../model。我甚至尝试使用.././model,这指向model的一个子项。\u revs\u info
{{#each model._revs_info}}
{{debug ../model}}
{{#if_eq status compare="available"}}
{{debug ../model}}
<a href="#list/{{model.id}}/{{rev}}">{{rev}}</a>
{{/if_eq}}
{{/each}}
{{debug}}
已从中复制
根据,
../path段引用的是父模板作用域,而不是一个
在上下文中升级。这是因为块帮助程序可以调用
块与任何上下文,因此“一级提升”的概念不是
特别有意义,但作为对父模板的引用除外
范围
每个块辅助对象定义一个范围,因此在if_eq中,层次结构看起来像
。/../model
,您将获得正确的上下文
一个基于你的代码的小提琴另一个调试激活的小提琴
/**
* If Equals
* if_eq this compare=that
*/
Handlebars.registerHelper('if_eq', function(context, options) {
if (context == options.hash.compare)
return options.fn(this);
return options.inverse(this);
});
Handlebars.registerHelper("debug", function(optionalValue) {
console.log("Current Context");
console.log("====================");
console.log(this);
if (optionalValue) {
console.log("Value");
console.log("====================");
console.log(optionalValue);
}
});