我确信这是非常基础的,但是我不能在{{#if_eq}}中使用../模型。我甚至尝试使用../../模型,它指向model._revs_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}} 已从https://github.com/danharper/Handlebars-Helpers/blob/master/helpers.js复制{{#if_eq}}
/**
* 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);
});已从http://thinkvitamin.com/code/handlebars-js-part-3-tips-and-tricks/复制{{debug}}
Handlebars.registerHelper("debug", function(optionalValue) {
console.log("Current Context");
console.log("====================");
console.log(this);
if (optionalValue) {
console.log("Value");
console.log("====================");
console.log(optionalValue);
}
});发布于 2012-07-21 19:24:32
根据Handlebars documentation on paths的说法,
../ path段引用了父模板作用域,而不是上下文中的上一级。这是因为块帮助器可以调用具有任何上下文的块,所以“上一级”的概念除了作为对父模板作用域的引用之外并没有特别的意义。
每个块帮助器定义一个作用域,因此在if_eq中,层次结构如下所示
指向祖父母../../model,您就会得到正确的上下文。
和一个基于你的代码的小提琴和另一个激活了调试的http://jsfiddle.net/aFGD6/1/
https://stackoverflow.com/questions/11562612
复制相似问题