Skip to content

Instantly share code, notes, and snippets.

@proxygear
Created August 15, 2013 14:36
Show Gist options
  • Save proxygear/6241315 to your computer and use it in GitHub Desktop.
Save proxygear/6241315 to your computer and use it in GitHub Desktop.
A select with marionette JS ?
ES.module 'Views', (Views, App, Backbone, Marionette, $, _)->
class Views.Select extends Marionette.ItemView
template: JST['select']
ui:
select: 'select'
events:
'change select': 'selected'
initialize: (options)->
@listenTo @model, 'reset', this.display, this
@selected = options.selected
display: ()->
this.ui.select.find('option').remove()
this.ui.select.append("<option value=''-> Pick one</option>")
for opt in @model.models
this.ui.select.append("<option value='#{opt.get('_id')}'>#{opt.get('name')}</option>")
@proxygear
Copy link
Author

Usage :

ES.Views.new(
  model: @aCollection,
  select: (event) ->
     alert event
)

@proxygear
Copy link
Author

And more simplicity:

events:
      'change select': '_selected'
    initialize: (options)->
      @listenTo @model, 'reset', this.display, this
      @selected = options.selected
    _selected: (event)->
      @selected $('select').val()

Usage

ES.Views.new(
  model: @aCollection,
  select: (id) ->
     alert id
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment