Created
May 15, 2015 00:21
-
-
Save pelonpelon/2fd055ec190cb49e37f4 to your computer and use it in GitHub Desktop.
Mithril: Dropdowns (select boxes)
This file contains hidden or 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 DropDownExample = { | |
controller: function () { | |
var ctrl = this | |
ctrl.data = m.prop([{ name: 'alice', id: 1}, { name: 'bob', id: 2 }]) | |
ctrl.selectedId = m.prop() | |
}, | |
view: function (ctrl) { | |
return m('select', { onchange: m.withAttr('value', ctrl.selectedId) }, [ | |
ctrl.data().map(function(person) { | |
return m('option', { value: person.id }, person.name) | |
}) | |
]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment