Skip to content

Instantly share code, notes, and snippets.

@Rodrigora
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rodrigora/18124bb513144a6ca4ef to your computer and use it in GitHub Desktop.
Save Rodrigora/18124bb513144a6ca4ef to your computer and use it in GitHub Desktop.
add support to array attributes to EmberJS models
DS.ArrayTransform = DS.Transform.extend
deserialize: (serialized)->
if Ember.typeOf(serialized) == "array"
serialized
else
[]
serialize: (deserialized)->
type = Ember.typeOf deserialized
if type is 'array'
deserialized
else if type == 'string'
deserialized.split(',').map (item) ->
jQuery.trim(item);
else
[]
PortfoliosApplication.register("transform:array", DS.ArrayTransform);
PortfoliosApplication.App = DS.Model.extend
availableSections: DS.attr('array')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment