0

配列からすべての要素を取得する方法を理解しましたが、最初の要素に属する要素を取得しようとして立ち往生しています。Backbone.js を使用していて、テンプレートの 1 つを編集しようとしています。私が取得しているトラック情報は、JSON ファイルからのものです。HTML ファイル内でこれを行うことはできますか、それとも .js ファイルを編集する必要がありますか?

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>
4

1 に答える 1