2012-07-19 3 views
2

이것은 매우 기본 적이라고 확신하지만 ../model inside {{#if_eq}}을 사용할 수 없습니다. 나는 ../../model을 사용해 보았고 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}}   

{{#if_eq}}https://github.com/danharper/Handlebars-Helpers/blob/master/helpers.js

/** 
* 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); 
}); 

{{debug}}에서 복사 한 내용은 Handlebars documentation on paths 따르면 http://thinkvitamin.com/code/handlebars-js-part-3-tips-and-tricks/

Handlebars.registerHelper("debug", function(optionalValue) { 
    console.log("Current Context"); 
    console.log("===================="); 
    console.log(this); 

    if (optionalValue) { 
    console.log("Value"); 
    console.log("===================="); 
    console.log(optionalValue); 
    } 
}); 

답변

4

로부터 복사 된

../ 경로 세그먼트가 부모 템플릿 범위를 참조하며 문맥에서 레벨이 하나가 아닌 입니다. 이는 블록 도우미가 모든 문맥을 사용하여 블록을 호출 할 수 있기 때문에 "1 레벨 업"이라는 개념은 범위 인 부모 템플릿에 대한 참조를 제외하고는 특히 의미가 없습니다 ( ). if_eq 계층 구조가

  1. 기본 템플릿처럼 보이는 너무

각 블록 도우미

  • 각 범위, 범위 if_eq
  • , 범위를 정의합니다.
  • 그랜드 부모를 가리키면 ../../model이며 올바른 컨텍스트를 얻습니다.

    코드에 기반한 피들 http://jsfiddle.net/aFGD6/ 디버그가 활성화 된 또 다른 코드 http://jsfiddle.net/aFGD6/1/