핸들 바를 읽으면 놀랍습니다. (뭔가 === 1 ...과 같이) 작은 로직을 가진 조건부를 넣지 못하게되어서 핸들 바 템플릿을 만드는 방법에 정말 고심하고 있습니다. .핸들 바 조건부
if {{price_type}} == 1
Example
else if {{price_type}} == 2
{{min_price}}
else
No price
어떻게 핸들 바에서 처리 되었습니까? 고마워요
핸들 바를 읽으면 놀랍습니다. (뭔가 === 1 ...과 같이) 작은 로직을 가진 조건부를 넣지 못하게되어서 핸들 바 템플릿을 만드는 방법에 정말 고심하고 있습니다. .핸들 바 조건부
if {{price_type}} == 1
Example
else if {{price_type}} == 2
{{min_price}}
else
No price
어떻게 핸들 바에서 처리 되었습니까? 고마워요
핸들 바 if-helper는 부울 값에서만 작동합니다. 따라서 조건부 연산을 수행하려면 자신 만의 도우미를 만들어야합니다.
{{#ifPriceType price_type min_type}}{{/ifPriceType}}
Handlebars.registerHelper("ifPriceType",function(price_type,min_type){
if(price_type==1){ return "Example";}
else if(price_type==2){ return min_type;}
else return "No price";
});
은 당신이하고 작동 왜 작동하는지 무엇을 말 follows-로서 상기 주어진 예에서이 도우미를 사용할 수 있습니다. – stealthjong
당신은 다음과 같은 템플릿 자체에서 얻을 수 있습니다 당신은 자신의 템플릿 헬퍼를 작성하여이 작업을 수행 할 수 있습니다
if {{price_type}} == 1
Example
else
if {{price_type}} == 2
{{min_price}}
else
No price
.
Handlebars.registerHelper('conditionalHelper', function(lValue, rValue, options) {
if (lValue == rValue) {
return options.fn(this);
}
return options.inverse(this);
});
이 헬퍼 두 값 '좌변'와 '를 rvalue'을 받아 이러한 값이 동일인지 아닌지에 참 또는 거짓 따라 반환합니다. 우리는
{{#conditionalHelper price_type 1}}
Example
{{else}}
{{#conditionalHelper price_type 2}}
{{min_price}}
{{else}}
No price
{{/conditionalHelper}}
{{/conditionalHelper}}
http://handlebarsjs.com/block_helpers.html –