Introduction
To attach a listener to our view, we use the “events” attribute of Backbone.View. Remember that event listeners can only be attached to child elements of the “el” property. Let us attach a “click” listener to our button.
Solution
Modify extended back bone view to include following. Type any value to search input box and click search button. You should get the input text on console.
//Note that input[id=search_button] is filtering all input elements to match id="search_button"
events: {
"click input[id=search_button]": "doSearch",
},
doSearch: function( event ){
// Button clicked, you can access the element that was clic\ kedwithevent.currentTarget
console.log( "Search for " + $("#search_input").val() );
},
Solution
Modify extended back bone view to include following. Type any value to search input box and click search button. You should get the input text on console.
//Note that input[id=search_button] is filtering all input elements to match id="search_button"
events: {
"click input[id=search_button]": "doSearch",
},
doSearch: function( event ){
// Button clicked, you can access the element that was clic\ kedwithevent.currentTarget
console.log( "Search for " + $("#search_input").val() );
},
No comments:
Post a Comment