【发布时间】:2018-07-22 05:51:44
【问题描述】:
已经通过这个 SO 解决方案(以及更多)但无济于事:
How to iterate over array of objects in Handlebars?
鉴于此:
feeds: [
{
name: "Guardian",
data: "empty"
},
{
name: "TechCrunch",
data: [
{
"title": "Instagram is testing screenshot alerts for stories",
"author": "Fitz Tepper"
},
{
"title": "A group of industry insiders are putting Russian election meddling up for ad awards",
"author": "Jonathan Shieber"
},
{
"title": "The Trump administration is reportedly moving to privatize the International Space Station",
"author": "Jonathan Shieber"
}
]
},
{
name: "BBC",
data: "empty"
}
]
如何从“数据”数组中获取“标题”信息? “feeds”对象正在渲染参数中传递给 .hbs。到目前为止,我已经能够提出以下内容,在 HTML/.hbs 页面上显示为空白:
.hbs
<div class="tab-pane fade in" id="{{name}}" role="tabpanel">
<div id="results">
<script id="data-template" type="text/x-handlebars-template">
<div>
{{#data}}
{{#each this}}
{{title}}
{{/each}}
{{/data}}
</div>
</script>
</div>
</div>
<script>
$(function () {
let source = $("#data-template").html();
let template = Handlebars.compile(source);
let html = template({{contents}});
$('#results').html(html);
}
);
</script>
感谢您对此进行调查!
【问题讨论】:
标签: handlebars.js