내 Handlebars 템플릿에서 조건문을 실행하려고합니다. 문제는 if 조건이 삽입되면 콘텐츠를 전혀 렌더링하지 않는다는 것입니다. isVideoAvailable이 어떤 도움에 감사드립니다Handlebars.js 조건문
에 해당하는 경우 디스플레이 비디오 버튼 :
<!DOCTYPE html>
<html>
<head>
<title>Handlebars.js example</title>
</head>
<body>
<div id="placeholder">This will get replaced by handlebars.js</div>
<script type="text/javascript" src="handlebars.js"></script>
<script id="myTemplate" type="text/x-handlebars-template">
{{#names}}
<div style="width:100%;border:2px solid red;">
<table style="width:100%;border:2px solid black">
<tr>
<td style="width:50%; border:2px solid yellow;">
<img src="{{itemImage}}"></img>
</td>
<td style="width:50%; border:2px solid green;">
<img src="btn_downloadAudio.png"></img><br><br>
<img src="btn_downloadPresentation.png"></img><br><br>
<img src="btn_downloadTranscript.png"></img><br><br>
<img src="btn_downloadVideo.png"></img><br><br>
</td>
</tr>
<tr>
<td colspan="2"><img src="{{itemType}}">
<label style="font-weight:bolder">{{itemTitle}}</label>
</td>
</tr>
<tr>
<td colspan="2">
<p>{{itemDescription}}</p>
</td>
</tr>
</table>
</div>
{{/names}}
</script>
<script type="text/javascript">
var source = document.getElementById("myTemplate").innerHTML;
var template = Handlebars.compile(source);
//alert(template);
var data = {
names: [
{ "itemImage": "authorImage.png",
"itemTitle": "Handlebars.js Templating for HTML",
"itemType": "icon_document.png",
"isAudioAvailable": "true",
"isPresentationAvailable": "true",
"isTranscriptAvailable": "true",
"isVideoAvailable": "false",
"itemDescription": "Rendeting HTML content using Javascript is always messy! Why? The HTML to be rendered is unreadable. Its too complex to manage. And - The WORST PART: It does it again and again and again! Loss: Performance, Memory, the DOM has to be re-drawn again each and every time a tag is added."}
]
};
document.getElementById("placeholder").innerHTML = template(data);
</script>
</body>
</html>
조건 :
여기 내 코드입니다. 당신이 뭔가 조건부로 표시 할 경우
감사합니다, ANKIT는
잘 작동하는 것 같습니다. http://jsfiddle.net/ambiguous/DAHKY/ –
@muistooshort 네, 렌더링은 문제가 없습니다. "isVideoAvailable"== "true"인 경우에만 비디오 단추를 렌더링하고 싶습니다. 거짓이라면 나는 그것을 숨기고 싶다. 이 작업을 수행 할 수 있습니까? –