简体   繁体   English

如何获取值以为在回送模型中定义的属性定义的描述字段

[英]How to get value to description field defined for a property defined in loopback model

I have the following model definition in a loopback project: ` 我在回送项目中具有以下模型定义:

{
  "name": "Program",
  "base": "PersistedModel",

  "properties": {
    "sId": {
      "type": "string",
      "required": true,
      "length": 20
    },
    "Category": {
      "type": "string",
      "length": 255,
      "description": "Category"
    },
    "ProgramName": {
      "type": "string",
      "length": 255,
      "description": "Program Name"
    },
    "Program_Status": {
      "type": "string",
      "length": 255,
      "description": "Program Status"
    }
  },
  "validations": [],
  "relations": {
    "account": {
      "type": "belongsTo",
      "model": "Account",
      "foreignKey": "Account__c",
      "primaryKey": "sId"
    },
  },
  "methods": {}
}

` `

I want to get value of description defined in field name in any other model. 我想获取在任何其他模型的字段名称中定义的描述的值。 Is there anyway in loopback or express.js to get it? 无论如何,在loopback或express.js中都可以得到它?

It's only possible via javascript code. 只能通过javascript代码进行。 I'm afraid there isn't a way to access json files properties from another json file. 恐怕没有办法从另一个json文件访问json文件属性。

In yourOtherModel.js yourOtherModel.js中

module.exports = function(yourOtherModel){
var programProps = yourOtherModel.app.models.Program.properties;

//Your props
var programDescription = programProps.Category.description;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM