我有我的渲染功能:
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);
}
在我的模板中,我试图在循环中使用 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}}
顺便说一句,我已经尝试过这个:
<a href="{{download_url}}?client_id={{../client_id}}" target="_blank">DOWNLOAD</a>