问题描述
我有两个模型 - 会话和测试(ember-data)
a会话has_many测试。
I have two models - sessions and tests (ember-data)
a Session has_many tests.
事情是在JSON中返回从服务器(不能更改)在会话对象中没有test_ids,所以我不能在模型中。
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.
我想要有能力,当我去#/ session / 4 - 具有另一个服务器API调用< server_address> / rest / sessions / 4 / tests
并具有tests属性
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
当前代码:
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;
}
});
推荐答案
您可以尝试覆盖 buildURL
为您的具体案例创建所需的正确URL,
You can try overriding buildURL
to create the correct URL you need for your specific case, this answer should help you
这篇关于emberdata访问服务器以获取其他数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!