Tuesday, 15 May 2012

ember.js - Trouble consuming json rest data in ember-data -



ember.js - Trouble consuming json rest data in ember-data -

i'm trying parse json dataset in ember info models throws error in het console:

uncaught typeerror: cannot phone call method '_create' of undefined ds.store.ember.object.extend.materializerecord ds.store.ember.object.extend.findbyclientid

what doing wrong here?

this info receive server:

{ "newsitems": [ { "date": "2013-02-10t15:00:00+01:00", "id": "1", "images": [ { "id": "1", "value": "image.jpg" }, { "id": "3", "value": "anotherimage.jpg" } ], "slug": "some-slug", "summary": "some summary", "text": "some text", "thumb": { "id": "2", "value": "someimage.jpg" }, "title": "some title", "type": "1", "videos": [ { "id": "aeopx8tmiui", "value": "aeopx8tmiui" }, { "id": "kxopviu98xo", "value": "kxopviu98xo" } ] } ] }

these models:

app.newsitemthumb = ds.model.extend({ value: ds.attr('string'), newsitem: ds.belongsto('app.newsitem') }); app.newsitemimage = ds.model.extend({ value: ds.attr('string'), newsitem: ds.belongsto('app.newsitem') }); app.newsitemvideo = ds.model.extend({ value: ds.attr('string'), newsitem: ds.belongsto('app.newsitem') }); app.newsitem = ds.model.extend({ slug: ds.attr('string'), type: ds.attr('string'), title: ds.attr('string'), summary: ds.attr('string'), text: ds.attr('string'), date: ds.attr('date'), thumb: ds.belongsto('app.newsitemthumb'), images: ds.hasmany('app.newsitemimage'), videos: ds.hasmany('app.newsitemvideo') });

for record, suggestions optimizing these models welcome. feels weird create 3 models video, images , thumb.

according this issue, error pops when don't specify explicit mapping hasmany relationship in adapter.

try defining store as

app.store = ds.store.extend({ revision: 11, adapter: ds.restadapter.extend({ serializer: ds.restserializer.extend({ init: function() { this._super(); this.map("app.newsitem", { images: { embedded: "load" }, videos: { embedded: "load" } }); } }) }) });

ember.js ember-data

No comments:

Post a Comment