继承模型的远程方法未在回送资源管理器中显示

Pra*_*aid 4 strongloop loopbackjs

我已经在环回中继承了这样的模型-

{
    "name": "MyModel",
    "base": "AnotherModel",
    "idInjection": false,
    "properties": {
      "value": {
        "type": "String"
      },
      "display": {
        "type": "String"
      }
    },
    "validations": [],
    "relations": {},
    "acls": [],
    "methods": []
}
Run Code Online (Sandbox Code Playgroud)

虽然我可以AnotherModelMyModel.js文件中调用所有的远程方法。但是,AnotherModel我的浏览器中没有显示的远程方法。如何使继承的模型的所有远程方法显示在资源管理器中?

Far*_*hat 5

发生这种情况的原因是,当您调用时AnotherModel.remoteMethod,它仅为该模型注册了该远程方法,而不为基于该模型的模型注册。要为所有基于AnotherModel的模型调用它,您可以执行以下操作:

var originalSetup = AnotherModel.setup;
AnotherModel.setup = function() { // this will be called everytime a 
  // model is extended from this model.

  originalSetup.apply(this, arguments); // This is necessary if your 
  // AnotherModel is based of another model, like PersistedModel.

  this.remoteMethod('yourMethod', {
    ..
  });
};
Run Code Online (Sandbox Code Playgroud)

我从这里学到了这一点,还检查了persistedModel如何在所有基于它的模型中将其作为远程方法。

由于此问题,还要确保基本模型是公共的。