emberdata access the server for additional data

扶醉桌前 提交于 2019-12-12 02:07:00

问题


I have two models - sessions and tests (ember-data)
a Session has_many tests.

The thing is that in the JSON returned from the server (cannot be changed) has no test_ids in session object so I can't have it in the model.

I want to have the ability when I go to #/session/4 - to have ember have another server API call to <server_address>/rest/sessions/4/tests and have it in a "tests" property

The current code:

App.Session = DS.Model.extend({
    logicalId: DS.attr('string'),
    .....
//  tests: DS.hasMany('test', {async: true}) - wish I could do this
});


App.SessionSerializer = DS.ActiveModelSerializer.extend({
    normalizePayload: function(payload) {
        payload.sessions = payload.result;
        delete payload.error;
        delete payload.result;
        delete payload.metadata;
        return payload;
    }
});

回答1:


You can try overriding buildURL to create the correct URL you need for your specific case, this answer should help you



来源:https://stackoverflow.com/questions/26584475/emberdata-access-the-server-for-additional-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!