I am working with Ember, and the following code gets JSON from api.php script and displays the results in a template. My question is why the script breaks when I change the getJSON function to use .done () instead of .then ()? I get the following error:
: Failed Error: Validation failed: Ember.CollectionView content must embed Ember.Array. You have passed the object of the object.
If I register a response.items object during a function, I get the same results in the console, so I'm curious how Ember interprets this differently.
App.IndexRoute = Ember.Route.extend({ model: function() { return App.Item.all(); } }); App.Item = Ember.Object.extend(); App.Item.reopenClass({ all: function() { return $.getJSON("api.php").then(function(response) { var items = []; response.items.forEach( function (item) { items.push( App.Item.create(item) ); }); return items; }); } });
source share