条目的回送POST数组?

问题描述 投票:0回答:1

我想在一个查询中插入10个条目,而对10个查询。

我读到可以通过发送这样的数组来做到这一点:enter image description here

但是我收到此错误:enter image description here

我需要设置一些东西吗?我根本不知道该怎么办。

带样本回购:https://github.com/mathias22osterhagen22/loopback-array-post-sample

编辑:people-model.ts:

import {Entity, model, property} from '@loopback/repository';

@model()
export class People extends Entity {
  @property({
    type: 'number',
    id: true,
    generated: true,
  })
  id?: number;

  @property({
    type: 'string',
    required: true,
  })
  name: string;


  constructor(data?: Partial<People>) {
    super(data);
  }
}

export interface PeopleRelations {
  // describe navigational properties here
}

export type PeopleWithRelations = People & PeopleRelations;

post loopbackjs loopback4
1个回答
0
投票
 async create(
    @requestBody({
      content: {
        'application/json': {
          schema: {
            type: 'array',
            items: getModelSchemaRef(People, {
                title: 'NewPeople',
                exclude: ['id'],
               }),
          }
        },
      },
    })
    ...restof logic 

您可以通过修改请求主体来传递人员模型的数组。如果需要更多帮助,可以发表评论。 “快乐回送:)”

© www.soinside.com 2019 - 2024. All rights reserved.