[英]Variable is undefined inside 'each' in Handlebars.js
I have my render function: 我有我的渲染功能:
renderTracksList = function(tracks){
var source = $("#timeline-template").html();
var template = Handlebars.compile(source);
var data = {
tracks: tracks,
client_id: App.config.client_id
};
var html = template(data);
$('#timeline').html(html);
}
And in my template I'm trying to use print client_id
inside the loop, but in the loop context it's undefined, so how to access and print the variable? 在我的模板中,我试图在循环中使用print
client_id
,但是在循环上下文中它是未定义的,那么如何访问和打印变量?
{{#each tracks}}
<div class="track">
{{title}} -
<a href="javascript:App.play('{{permalink_url}}')">PLAY</a>
{{#if downloadable}}
- <a href="{{download_url}}?client_id={{client_id}}" target="_blank">DOWNLOAD</a>
{{/if}}
</div>
{{/each}}
Btw, I've already tried this: 顺便说一句,我已经尝试过了:
<a href="{{download_url}}?client_id={{../client_id}}" target="_blank">DOWNLOAD</a>
Try to repeat ../
for both the {{#if}}
and the {{#each}}
: 尝试对
{{#if}}
和{{#each}}
重复../
:
<a href="{{download_url}}?client_id={{../../client_id}}" target="_blank">DOWNLOAD</a>
Even though {{#if}}
keeps the value of the previous context, it still creates another entry in the stack that ../
steps back through. 尽管
{{#if}}
保留了前一个上下文的值,但它仍然会在堆栈中创建另一个条目,以便... ../
退回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.