Reputation: 7043
I am trying to do some experimenting with Ember js. Instead of fixtures I would like to use an API.
This is my code which I am using to get the data:
App.ItemsRoute = Ember.Route.extend({
model: function() {
return $.getJSON('http://someurl.json').then(function(data) {
return data.items_popular.map(function(item) {
return item;
});
});
}
});
This is what the json file looks like:
{
"popular":{
"items_popular":[
{
"id":"23",
"item":"Some title",
"url":"http://url",
"user":"girl"
},
{
"id":"56",
"item":"Title of item 2",
"url":"http://url",
"user":"guy"
}
]
}
}
Currently I keep getting an
Cannot call method 'map' of undefined
Would appreciate any help with refactoring my request
Upvotes: 0
Views: 69
Reputation: 27012
You're accessing data.items_popular
, but it should be data.popular.items_popular
.
Demo: http://jsfiddle.net/rmfRt/
Upvotes: 2