Skip to content

Instantly share code, notes, and snippets.

@onerinas
Forked from pelonpelon/dropdown_select.js
Created January 25, 2019 18:23
Show Gist options
  • Save onerinas/12adcc6439e381ada59ee8aab52f8156 to your computer and use it in GitHub Desktop.
Save onerinas/12adcc6439e381ada59ee8aab52f8156 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