我正在尝试使用Loopback来获取与Ember交谈的API.
Ember要求JSON包含在"密钥"中,例如帐户:
{ account:
{ domain: 'domain.com',
subdomain: 'test',
title: 'test.domain.com',
id: 1
} }
Run Code Online (Sandbox Code Playgroud)
我已经在Google小组上找到了一些关于如何改变响应的建议,以便Ember将使用afterRemote挂钩接收它.
例如在我的models/account.js中:
module.exports = function(Account) {
Account.afterRemote('**', function (ctx, account, next) {
if(ctx.result) {
if(Array.isArray(ctx.result)) {
ctx.res.body = { 'accounts': account };
} else {
ctx.res.body = { 'account': account };
}
}
console.log(ctx.res.body);
next();
});
};
Run Code Online (Sandbox Code Playgroud)
我看到响应是应该在控制台中的..但是localhost:3000/api/accounts中的JSON输出不显示更改的JSON对象.
在Loopback中更改JSON响应/请求的正确方法是什么?
理想情况下,它可以应用于所有模型.