Skip to content

Instantly share code, notes, and snippets.

@pelonpelon
Created May 15, 2015 00:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pelonpelon/2fd055ec190cb49e37f4 to your computer and use it in GitHub Desktop.
Save pelonpelon/2fd055ec190cb49e37f4 to your computer and use it in GitHub Desktop.
Mithril: Dropdowns (select boxes)
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