Created
April 25, 2012 16:12
-
-
Save cloke/2490991 to your computer and use it in GitHub Desktop.
Select Element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{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