[英]How to select json item un handlebar
How can I select an element in a json array in Handlebarjs I tried navigating the each but the position of the element in the array. 我如何在Handlebarjs中的json数组中选择一个元素,我尝试导航每个元素,但定位元素在数组中的位置。 Json array Json数组
#each
takes an array to iterate over, so passing it media.thumbnails[1]
won't work, as that is the second object in the array. #each
需要一个数组进行迭代,因此将media.thumbnails[1]
传递给它是media.thumbnails[1]
,因为那是数组中的第二个对象。 Try passing it the array media.thumbnails
尝试将其传递给数组media.thumbnails
i hope to solve your problem, otherwise pass me the complete code 我希望能解决您的问题,否则请将完整的代码传递给我
<div id="handlebarsDetail"> </div>
<script id="handleMarkup" type="text/x-handlebars-template">
{{#each media.thumbnails}}
<figure>
<img src="{{url}}" />
</figure>
{{/each}}
</script>
var sourceHandlebars = $("#handleMarkup").html();
var templateHandlebars = Handlebars.compile(sourceHandlebars);
$.getJSON("urlFileJson", function (data) {
var $htmlHandlebars = jQuery(templateHandlebars(data));
$("#handlebarsDetail").empty().append($htmlHandlebars);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.