如何使用 cli b4 模型命令在 Loopback 4 中处理嵌套对象
How can I work with Nested Objects in Loopback 4 using the cli b4 model command
我正在处理深层嵌套对象,我需要为使用 lb4 建模。我有机会获得有关此示例 JSON 代码的帮助吗?
{
"cardAcceptor": {
"address": {
"city": "Foster City",
"country": "RU",
"county": "San Mateo",
"state": "CA",
"zipCode": "94404"
},
"idCode": "ABCD1234ABCD123",
"name": "ABCD",
"terminalId": "ABCD1234"
},
"destinationCurrencyCode": "840",
"markUpRate": "1",
"retrievalReferenceNumber": "201010101031",
"sourceAmount": "100",
"sourceCurrencyCode": "643",
"systemsTraceAuditNumber": "350421"
}
您可以为嵌套对象创建单独的模型,
以上数据结构为例
你可以有类似的东西
export class CardAcceptor extends Address {
@property({
type: 'string',
required: true,
})
address: string;
@property({
type: 'string',
required: true,
})
idCode: string
@property({
type: 'string',
required: true,
})
name: string;
@property({
type: 'string',
required: true,
})
terminalId: string;
constructor(data?: Partial<CardAcceptor>) {
super(data);
}
}
export class Address extends Entity {
@property({
type: 'string',
required: true,
})
city: string;
@property({
type: 'string',
required: true,
})
country: string
@property({
type: 'string',
required: true,
})
county: string;
@property({
type: 'string',
required: true,
})
state: string;
@property({
type: 'boolean',
required: true,
})
zipCode: boolean;
constructor(data?: Partial<Address>) {
super(data);
}
}
export class BaseModel extends CardAcceptor {
@property.array(CardAcceptor)
cardAcceptor: CardAcceptor;
@property({
type: 'string',
required: true,
})
destinationCurrencyCode: string;
@property({
type: 'string',
required: true,
})
markUpRate: string
@property({
type: 'string',
required: true,
})
retrievalReferenceNumber: string;
@property({
type: 'string',
required: true,
})
sourceAmount: string;
@property({
type: 'boolean',
required: true,
})
sourceCurrencyCode: boolean;
@property({
type: 'array',
itemType: 'string',
default: [],
})
systemsTraceAuditNumber?: string[];
constructor(data?: Partial<Game>) {
super(data);
}
}
希望这对您有所帮助。
谢谢
我正在处理深层嵌套对象,我需要为使用 lb4 建模。我有机会获得有关此示例 JSON 代码的帮助吗?
{
"cardAcceptor": {
"address": {
"city": "Foster City",
"country": "RU",
"county": "San Mateo",
"state": "CA",
"zipCode": "94404"
},
"idCode": "ABCD1234ABCD123",
"name": "ABCD",
"terminalId": "ABCD1234"
},
"destinationCurrencyCode": "840",
"markUpRate": "1",
"retrievalReferenceNumber": "201010101031",
"sourceAmount": "100",
"sourceCurrencyCode": "643",
"systemsTraceAuditNumber": "350421"
}
您可以为嵌套对象创建单独的模型,
以上数据结构为例
你可以有类似的东西
export class CardAcceptor extends Address {
@property({
type: 'string',
required: true,
})
address: string;
@property({
type: 'string',
required: true,
})
idCode: string
@property({
type: 'string',
required: true,
})
name: string;
@property({
type: 'string',
required: true,
})
terminalId: string;
constructor(data?: Partial<CardAcceptor>) {
super(data);
}
}
export class Address extends Entity {
@property({
type: 'string',
required: true,
})
city: string;
@property({
type: 'string',
required: true,
})
country: string
@property({
type: 'string',
required: true,
})
county: string;
@property({
type: 'string',
required: true,
})
state: string;
@property({
type: 'boolean',
required: true,
})
zipCode: boolean;
constructor(data?: Partial<Address>) {
super(data);
}
}
export class BaseModel extends CardAcceptor {
@property.array(CardAcceptor)
cardAcceptor: CardAcceptor;
@property({
type: 'string',
required: true,
})
destinationCurrencyCode: string;
@property({
type: 'string',
required: true,
})
markUpRate: string
@property({
type: 'string',
required: true,
})
retrievalReferenceNumber: string;
@property({
type: 'string',
required: true,
})
sourceAmount: string;
@property({
type: 'boolean',
required: true,
})
sourceCurrencyCode: boolean;
@property({
type: 'array',
itemType: 'string',
default: [],
})
systemsTraceAuditNumber?: string[];
constructor(data?: Partial<Game>) {
super(data);
}
}
希望这对您有所帮助。 谢谢