javascript - Ember-data cannot read property 'length' of undefined -
i'm trying data api server ember-data ,i added ember-data ember starter-kit.
getting
app = ember.application.create(); app.router.map(function() { // put routes here }); app.applicationadapter = ds.restadapter.extend({ namespace: 'emberjs/ember.js', host : 'https://api.github.com/repos' }); app.store = ds.store.extend({ adapter: 'app.applicationadapter' }); app.indexroute = ember.route.extend({ model: function() { return this.store.find('pull'); } }); app.pull = ds.model.extend({ url : ds.attr(), title : ds.attr(), body : ds.attr() });
giving same error every request. try github, gives same error.
api connected: github api
error while processing route: index cannot read property 'length' of undefined typeerror: cannot read property 'length' of undefined
ember expects pluralised root object when returning multiple results, in case pulls
, i.e
{ "pulls": [...] }
as you're working api don't control you'll need change data embers expected format modified serializer so:
/app/serializers/pull.js
import ds "ember-data"; export default ds.restserializer.extend({ normalizepayload: function(payload) { if(array.isarray(payload)) { return {"pulls": payload }; } return payload; } });
information on serializer: http://emberjs.com/api/data/classes/ds.restserializer.html
Comments
Post a Comment