Reputation: 579
I'm trying to populate an emberJS model via results from a remote API (http://docs.themoviedb.apiary.io/).
The request string is https://api.themoviedb.org//3/movie/popular?api_key={{KEY}}
It returns records in this format:
{"page":1,"results":[{"adult":false,"backdrop_path":"/8aZHR0wXacn5DVYK3cS2ozWYPCN.jpg","id":64686,"original_title":"47 Ronin","release_date":"2013-12-25","poster_path":"/v9JCVROrdlHZCWP3D6pnV8Xc29w.jpg","popularity":97.4338866047715,"title":"47 Ronin","vote_average":6.4,"vote_count":78}],"total_pages":7834,"total_results":156677}
This gets recent popular movies.
I have a model set up
App.Movie = DS.Model.extend({
title: null
});
So far I've been using fixtures but now I want to be able to pull in data from the API and populate it that way.
I've had a look at a few examples but I can't seem to get my head around it (apologies, I'm relatively new to Ember and backend in general)
Upvotes: 0
Views: 514
Reputation: 3952
I think your model should be this:
App.Movie = DS.Model.extend({
title: DS.attr('string')
});
You also need to setup the deserialization since, if I am not mistaken, the REST adapter expects the format to be:
{ "movie": {
"page" : 1,
...
}
}
Upvotes: 0
Reputation: 746
I think you'd do something like this
store.createRecord('movie', {
title: json_response.original_title
});
where store is your DS.Store
Upvotes: 1