Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. SC.Select = SC.CollectionView.extend({
  2.   tagName: 'select',
  3.   value: '',
  4.   itemViewClass: SC.View.extend({
  5.     tagName: 'option',
  6.     displayProperty: false,
  7.     valueProperty: false,
  8.     applyAttributesToBuffer: function(buffer){
  9.       if (this.get('valueProperty')) {
  10.         buffer.attr('value', this.get('content')[this.valueProperty]);
  11.       }
  12.       return this._super(buffer);
  13.     },
  14.     displayValue: function(){
  15.       return this.get('content')[this.displayProperty];
  16.     }.property('content'),
  17.     defaultTemplate: SC.Handlebars.compile('{{displayValue}}')
  18.   }),
  19.   change: function() {
  20.     SC.run.once(this, this._updateSelection);
  21.     return false;
  22.   },
  23.   _updateSelection: function() {
  24.     var selection = this.$('option:selected');
  25.     SC.set(this, 'value', selection.prop('value'));
  26.   }
  27. });