如何在环回中将模型设置为变量?

How to set a model to a variable in loopback?

休闲码returns型号列表 var 模型 = app.models();

models.forEach(function(Model) {
 console.log(Model.modelName); 
});
User        
AccessToken
ACL
RoleMapping 
Role        
Registration
Assets

当我使用休闲代码来使用 Registration 或 Asstes 时:

D:\apps\newapps\testapp\node_modules\loopback\lib\application.js:129
    assert(Model.prototype instanceof Model.registry.getModel('Model'),
                ^

TypeError: Cannot read property 'prototype' of undefined
    at Function.app.model (D:\apps\newapps\testapp\node_modules\loopback\lib\application.js:129:17)
    at Object.<anonymous> (D:\apps\newapps\testapp\server\server.js:38:5)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3

我不是环回专家,但试试这个代码:

var Registration = app.models.Registration;
console.log(Registration);
app.model(Registration);

用户是模型名称。

var user = app.models.User;

resetPassword为用户模型函数名, 取两个参数 new_pwdtoken,

user.resetPassword({
          new_pwd: new_password,
          token
        }, (err, data) => {
          if (err || !data.status) {
            return err || data;
          } else {
            return data;
          } 
        });