Skip to content

Instantly share code, notes, and snippets.

@edwardhotchkiss
Created July 14, 2012 13:12
Show Gist options
  • Save edwardhotchkiss/3111251 to your computer and use it in GitHub Desktop.
Save edwardhotchkiss/3111251 to your computer and use it in GitHub Desktop.
/**
* @application
* @file /app/helpers/models.js
**/
Spine.Model.extend({
toJSON: function(){
var attributes = this.attributes();
attributes['id'] = attributes['_id'];
return attributes;
},
fromJSON: function(objects) {
var results;
if (!objects) {
return;
};
if (typeof objects === 'string') {
objects = JSON.parse(objects);
};
if (isArray(objects)) {
results = [];
for (var i = 0; i < objects.length; i++) {
var value = objects[i];
value['id'] = value['_id'];
results.push(new this(value));
};
return results;
} else {
return new this(objects);
};
}
});
/* EOF */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment