Created
July 14, 2012 13:12
-
-
Save edwardhotchkiss/3111251 to your computer and use it in GitHub Desktop.
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
/** | |
* @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