【发布时间】:2017-11-12 16:21:55
【问题描述】:
feathersjs 文档中提供的解释如下:
pluck 丢弃除指定字段之外的所有字段,无论是来自 提交的数据或来自结果的数据。如果数据是数组或 分页查找结果钩子将删除每个字段 项目。
import _pluck from '../common/_pluck';
import checkContextIf from './check-context-if';
import getItems from './get-items';
import replaceItems from './replace-items';
export default function (...fieldNames) {
return context => {
checkContextIf(context, 'before', ['create', 'update', 'patch'], 'pluck');
if(context.params.provider) {
replaceItems(context, _pluck(getItems(context), fieldNames));
}
return context;
};
}
getItems 实用程序返回 hook.data 或 hook.result 取决于钩子是用作之前还是 钩后。为查找返回 hook.result.data 或 hook.result 方法。
返回的项目总是一个数组以简化进一步的处理。
replaceItems 实用程序与 getItems 相反,返回 他们来自哪里。
我的问题与 checkContextIf 函数有关。这个函数防止 pluck 钩子被调用,除非在 create、update 和 patch 方法之前。那么 pluck 钩子如何对查询结果起作用。结果不是在服务调用后产生并在后挂钩中处理吗?
【问题讨论】:
标签: hook feathersjs pluck