[英]Backbone.js Get First Element from JSON file
while I figured out how to get the all of the elements from an array, I am stuck on trying to get an element belonging to the first. 虽然我想出了如何从数组中获取所有元素的方法,但我仍坚持尝试获取属于第一个元素的元素。 I am using Backbone.js and trying to edit one of my templates. 我正在使用Backbone.js并尝试编辑我的模板之一。 The track information I am getting is coming from a JSON file. 我得到的曲目信息来自JSON文件。 Can I do this within my HTML file or must I edit my .js file? 我可以在HTML文件中执行此操作,还是必须编辑.js文件?
HTML: HTML:
<script type="text/template" id="lesson-template">
<span class="lesson-title"><%= title %></span>
<select class="sel">
<% _.each(tracks, function(track) { %> //this lets me loop through each of them
<option value = "<%= track.text %>" ><%= track.title %></option>
<% }); %>
</select>
//Now I want to figure out a way to just get the track.text of the first track here and put it in tracktext!
<p id="tracktext">Hello World!</p>
</script>
<p id="tracktext"><%= tracks[0].text %></p>
You don't appear to be using backbone collections or models here. 您似乎在这里没有使用骨干集合或模型。 Is this just a question about javascript and underscore templates perhaps? 这可能只是关于javascript和下划线模板的问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.