Created
May 13, 2015 13:21
-
-
Save yevgenko/2a729ee83e11fe5277a0 to your computer and use it in GitHub Desktop.
Simple SelectView: Triggers Event and Returns Model When Chosen http://www.beardedhacker.com/blog/2015/05/13/simple-selectview-triggers-event-and-returns-model-when-chosen/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<header> | |
<script type="text/html" id="options-template"> | |
<% for (i = 0; i < items.length; i++) { %> | |
<option value="<%= items[i].id %>"><%= items[i].value %></option> | |
<% } %> | |
</script> | |
</header> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SelectView = Marionette.ItemView.extend({ | |
template: "#options-template", | |
tagName: "select", | |
events: { | |
'change' : 'optionSelected' | |
}, | |
optionSelected: function(e){ | |
this.trigger('item:chosen', this.collection.get(e.target.value)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment