如何通过 HTTP 请求在 strapi 中添加可重复组件

How to add repeatable component in strapi via HTTP request

最初,消息字段(Strapi 可重复组件)将如下所示。

"messages":[
    {
        "from": "user1",
        "_id": "5f787348628eea0017b49f7e",
        "text": "happy hello world",
        "createdAt": "2020-10-03T12:49:12.052Z",
        "updatedAt": "2020-10-03T12:49:12.052Z",
        "__v": 0,
        "id": "5f787348628eea0017b49f7e"
    }
]

我想向可重复组件添加另一条消息:

"messages":[
    {
      "from": "user2",
      "text": "happy hello world"
    }
  ]

当我通过 curl 放置它时:

curl -i -X PUT \
   -H "Content-Type:application/json" \
   -d \
'{
  "messages":[
    {
      "from": "shop",
      "text": "happy hello world"
    }
  ]
}' \
 'https://myserver/mes/5f781bdd23e08f001732cdd8'

它覆盖了之前的消息。如何在不丢失任何先前数据的情况下添加另一条消息?

您必须像以前一样用 PUT 发送所有数组。

{
    "id": "5f781bdd23e08f001732cdd8",
    "messages": [
        {
            "id": "5f787348628eea0017b49f7e",
            "from": "user1",
            "text": "happy hello world"
        },
        {

            "from": "shop",
            "text": "happy hello world"
        }
    ]
}

看起来 Strapi 不知道你是想更新第一个,还是删除它,或者创建一个新的...