2017-09-09 5 views
1

fallowing 코드는 모델 목록을 반환합니다. var models = app.models(); 루프백에서 모델을 변수로 설정하는 방법은 무엇입니까?

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

내가 등록 또는 Asstes 사용 fallowing 코드를 사용하여 :

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 

답변

1

사용자는 모델 이름입니다.

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 - 바 트라, 큰 도움을 사용자 모델의 함수 이름입니다. Txx – RSA

2

내가 루프백의 전문가가 오전하지만이 코드를 시도 :

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