Loopback Strongloop 从模型实例中获取 ModelName
Loopback Strongloop get ModelName from model instance
我需要使用环回从模型实例中获取模型名称。有什么想法吗?
var myAccount = new app.models.Account({name: 'ACME'});
var modelName = myAccount.modelName;`
//should get 'Account'
我设法通过使用(这是模型)检索模型名称:
this.definition.name;
正确答案是 instance.constructor.definition.name
,所以在你的情况下 myAccount.constructor.definition.name
我需要使用环回从模型实例中获取模型名称。有什么想法吗?
var myAccount = new app.models.Account({name: 'ACME'});
var modelName = myAccount.modelName;`
//should get 'Account'
我设法通过使用(这是模型)检索模型名称:
this.definition.name;
正确答案是 instance.constructor.definition.name
,所以在你的情况下 myAccount.constructor.definition.name