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

问题描述:

休闲代码返回模型列表 var models = app.models();如何将模型设置为环回的变量?

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

当我使用休耕代码使用登记或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 user = app.models.User; 

resetPassword是用户模式,它 需要两个参数new_pwd令牌

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

喜@ shubham,巴特拉,有很大的帮助的功能名称。 TNX – RSA

我不回送的专家,但试试这个代码:

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