ember.js - ember JSONAPIAdapter fails to load data properly into store -
i using ember-cli , ember-data 1.13.7 , jsonapiadapter. use http-mock mock data during local testing. worked when used restadapter, ran problem when switching jsonapiadapter.
the problem records data not loaded store , error reading undefined property.
the adpater looks this:
import ds 'ember-data'; export default ds.jsonapiadapter.extend({ namespace: 'api', });
the ajax call this:
http://localhost:4200/api/users/1
the http-mock looks this:
usersrouter.get('/:id', function(req, res) { res.send({ 'users': { id: req.params.id, firstname: "john", lastname: "doe", email: "johndoe@example.com", mobile: "12345678", nextappointment: 1 } }); });
the response looks this:
{"users":{"id":"1","firstname":"john","lastname":"doe","email":"johndoe@example.com","mobile":"12345678","nextappointment":1}}
the response data islooking problem response header status code of 304, , fact data not loaded store. object id=1 created, properties in object 'undefined' when @ stores data in ember inspector.
update:
the error is:
error while processing route: home.index cannot read property '_internalmodel' of undefined typeerror: cannot read property '_internalmodel' of undefined
update 2: turns out 304 not important. model still not loaded store when httpcode 200 either. fund call works fine:
http://localhost:4200/api/users
while call fails:
http://localhost:4200/api/users/1
they return same json response.
your call for:
http://localhost:4200/api/users
can't return exactly same json response
.
your call for: http://localhost:4200/api/users/1
should return:
{ "data": { "id":"1", "type": "user", "attributes" : { "firstname":"john", "lastname":"doe", "email":"johndoe@example.com", "mobile":"12345678", "nextappointment":1 } } }
read more jsonapiadapter:
Comments
Post a Comment