I am trying to create app with loopback, my problem is fields filters. It does not work. It return all data from database. Im using mysql connector.
我正在尝试使用loopback创建应用程序,我的问题是字段过滤器。这是行不通的。它返回数据库中的所有数据。我使用mysql连接器。
'use strict';
module.exports = function(Dog) {
Dog.observe('loaded', function doStuf(ctx, next) {
Dog.find({fields: {breed: true}}, function(err, data) {
});
next();
});
};
I want to return to client response like:
我想回到客户端响应,如:
{
"breed": "labrador"
},
{
....
}
1 个解决方案
#1
0
According to the docs for loaded (https://loopback.io/doc/en/lb2/Operation-hooks.html), the loaded function lets you modify data before returning it to an operation. Your use of find() does nothing. I mean nothing relevant. You want to modify data itself. So try changing ctx.data
. You can remove or add keys there.
根据加载的文档(https://loopback.io/doc/en/lb2/Operation-hooks.html),加载的函数允许您在将数据返回到操作之前修改数据。你使用find()什么都不做。我的意思是没有相关性您想要自己修改数据。所以尝试更改ctx.data。您可以在那里删除或添加密钥。
#1
0
According to the docs for loaded (https://loopback.io/doc/en/lb2/Operation-hooks.html), the loaded function lets you modify data before returning it to an operation. Your use of find() does nothing. I mean nothing relevant. You want to modify data itself. So try changing ctx.data
. You can remove or add keys there.
根据加载的文档(https://loopback.io/doc/en/lb2/Operation-hooks.html),加载的函数允许您在将数据返回到操作之前修改数据。你使用find()什么都不做。我的意思是没有相关性您想要自己修改数据。所以尝试更改ctx.data。您可以在那里删除或添加密钥。