带对象的环回模型 [英] loopback model with object
问题描述
晚上好
我只是从环回开始(从字面上看),所以我去了文档中解释的命令:
I just started with loopback (literally), so I went for the commands explained in the documentation:
使用以下命令启动回送项目:
Started the loopback project with the command:
slc loopback
使用环回模型生成器通过以下命令生成模型:
Generated a model with the loopback model generator with the command:
slc loopback:model
当生成器启动时,它会询问模型名称,存储方法,基类,复数形式,是我们希望将其作为通用模型还是服务器模型.之后,它询问模型的属性.
When the generator starts, it asks for model name, storing method, base class, plural, whether we want it to be a common model or a server model. After that it asks for the properties of the model.
我有一个像这样的模型:
I have a model that could be like this:
MODEL NAME
Property1 : String,
Property2 : String,
Property3 : Number,
Property4 : {
obj.Property1 : String,
obj.Property2 : String,
obj.Property3 : String
},
Property5 : String
我认为,通过选择对象"作为属性类型,它会询问我该对象的其他属性,但事实并非如此.现在,我不知道如何创建该模型对象内部的其他属性.
I thought that by choosing "Object" as the type of property it would ask me for additional properties on that object, but it didn't. Now I have no idea how to create those additional properties that are inside the object of this model.
我将如何创建嵌套在Property4 Object
内部的属性?我是否从loopback:model
生成器中丢失了某些内容?
How would I go about creating the properties that are nested inside the Property4 Object
? Am I missing something from the loopback:model
generator?
推荐答案
好吧slc loopback:model
不能这样做.您只需要在properties
对象中的生成的json文件中指定自己(可能在common/models/目录中):
Well slc loopback:model
doesn't do that. You just have to specify yourself in the generated json file(possibly in common/models/ directory) in the properties
object:
"properties": {
...
"Property4": {
"type": {
"Property1" : "String",
"Property2" : "String",
"Property3" : "String"
}
},
...
}
如果您需要任何属性,可以这样:
If you want any of the properties to be required you can do it like this:
"properties": {
...
"Property4": {
"type": {
"Property1" : {
"type": "String"
"required": true
},
"Property2" : "String",
"Property3" : "String"
}
},
...
}
如果对象没有"type"属性,则可以执行以下操作:
If the object doesn't have a "type" property, you can just do this:
"properties": {
...
"Property4": {
"Property1" : "String",
"Property2" : "String",
"Property3" : "String"
},
...
}
您还可以将此定义放入另一个模型中,并在此处引用:
You can also put this definition into a another model and reference that here:
"properties": {
...
"Property4": "AnotherModel",
...
}
我建议您通读属性"本文档的第二部分以及对象类型"本文档的一部分.
这篇关于带对象的环回模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!