아래는 html 요소를 포함하는 핸들 바 템플릿입니다.
{{#show}} <div class="intro">dummy</div> <div class="body">text</div> {{/show}}
다음은 도우미 클래스입니다.
Handlebars.registerHelper('show', function() { return true; });
html 요소는 show 가 true 인 경우에만 표시되어야 합니다.
누구든지이 문제를 해결할 수 있습니까?
블록 도우미는 그렇게 작동하지 않습니다. 블록 도우미는 options
내부에 두 가지 관심 기능이 있는 객체를 전달 합니다.
options.fn
: 블록을 나타냅니다.options.inverse
: {{else}}
블록을 나타냅니다 .그래서 당신의 show
도우미는 return true
해서는 안됩니다 return options.fn()
. 더 비슷한 것 :
Handlebars.registerHelper('show', function(options) {
if(some_condition)
return options.fn(this);
else
return options.inverse(this);
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다