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. The track information I am getting is coming from a JSON file. Can I do this within my HTML file or must I edit my .js file?
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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.