Models
AJAX Abstraction for a Single Resource
AJAX Abstraction for a Single Resource
The toJSON()
method returns a copy of the model's attributes.
The default implementation looks like this:
import _ from 'lodash';
...
toJSON: function(options) {
return _.clone(this.attributes);
},
Let's say you have a model that looks like this:
import { Model } from 'lore-models';
const Tweet = Model.extend({
urlRoot: 'http://localhost:1337/tweets'
})
const tweet = new Tweet({
id: 1,
text: 'Some tweet'
});
Then invoking tweet.toJSON()
would return this:
{
id: 1,
text: 'Some tweet'
}