如何在环回中为 GET 和 POST 方法定义单独的隐藏道具?

How to define separate hidden props for GET and POST methods in loopback?

我希望在环回资源管理器中的 GET 方法可以看到一些道具,但我不想为 POST 方法显示它们,例如id 属性。如何在环回中完成?

没有用于此的内置方法。

您需要在远程之后为每个您想要不同于默认方法的远程方法执行此操作。

Model.afterRemote('GetMethod', function(ctx, instance, next){
  var instance = ctx.result;
  //reshape it
  ctx.result = instance;
  next();
});

更新

如果您想在资源管理器组件中影响它,那么您需要使用 null 数据源创建单独的模型,仅用于显示模式并在远程方法的定义中使用它。

Model.remoteMethod('GetMethod', {
    accepts: [
      {
        arg: 'req',
        type: 'Object',
        required: true,
        http: {source: 'req'}
      }
    ],
    returns: {root: true, type: 'ModelDTOForSHow'},
    http: {verb: 'get', status: 200, path: '/getter'}
  });

ModelDTOForShow 中你隐藏了一些道具,在另一个中隐藏了一些其他道具