Skip to content

Instantly share code, notes, and snippets.

@cloke
Created April 25, 2012 16:12
Show Gist options
  • Save cloke/2490991 to your computer and use it in GitHub Desktop.
Save cloke/2490991 to your computer and use it in GitHub Desktop.
Select Element
{{view M.Select
contentBinding="Desires.elementTypeController"
valueBinding="this.type"
optionLabelPath="content.label"
optionValuePath="content.type"
classNames="input-xlarge"
}}
M.Select = Em.Select.extend({
value: Ember.computed(function(key, value){
var content = this.get('content'),
selection = this.get('selection'),
self = this,
path = this.get("optionValuePath").split(".")[1];
if (value != undefined){
content.forEach(function(item, idx){
if (item[path] && item[path] == value) {
self.set('selection', item);
return;
}
});
return value;
}
if ( selection && this.bindingContext.get('isLoaded')) {
this.setPath('bindingContext.' + path, selection[path])
}
return selection ?
this.get('selection')['path'] :
null;
}).property('selection').cacheable()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment