Backbone.js Change text based on selected drop-down list

I try to change the text when the user selects another option from the drop-down list. I am using Backbone.js and trying to figure out how to get the text belonging to the track when the user selects an option.

As a continuation, if I did not set the value of the track.text option, but rather track.title, how could I get it from a .js file? I originally set track.title and track.text in a JSON file. I am trying to learn how to get information from JSON files. Thank!!

window.LibraryLessonView = LessonView.extend({
events: {
    "change .sel " : "changeText"
},

changeText: function() {
//not sure what I should write here...
}


});

This is in my HTML file:

    <script type="text/template" id="lesson-template">
         <span class="lesson-title"><%= title %></span>
         <select class="sel">

//get the tracks from the JSON file and put them all in the dropdown
            <% _.each(tracks, function(track) { %>
              <option value = <%= track.title %> ><%= track.title %></option>


          <% }); %>        
          </select>

<p> Blah </P> //I want to change the text here

        </script>
0
source share
1 answer

[Changed] which should work for you:

changeText: function(e) {
    alert(e.target.value); 
}

e.target DOM, . e.target.value

+3

All Articles