Last active
August 29, 2015 14:04
-
-
Save vaclavbohac/7577546712cad39040f2 to your computer and use it in GitHub Desktop.
Select \w Optional Groups
This file contains 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
var get = Ember.get, | |
forEach = Ember.EnumerableUtils.forEach; | |
Ember.Select.extend({ | |
templateName: 'optional-groups-select', | |
groupedContent: Ember.computed(function() { | |
var groupPath = get(this, 'optionGroupPath'); | |
var groupedContent = Ember.A(); | |
var content = get(this, 'content') || []; | |
forEach(content, function(item) { | |
var label = get(item, groupPath); | |
if (label) { | |
if (get(groupedContent, 'lastObject.label') !== label) { | |
groupedContent.pushObject({ | |
label: label, | |
content: Ember.A() | |
}); | |
} | |
get(groupedContent, 'lastObject.content').push(item); | |
} else { | |
groupedContent.pushObject(item); | |
} | |
}); | |
return groupedContent; | |
}).property('optionGroupPath', 'content.@each') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment