如何通过HTTP请求在trapi中添加可重复组件 [英] How to add repeatable component in strapi via HTTP request
本文介绍了如何通过HTTP请求在trapi中添加可重复组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最初,消息字段(一个 Strapi 可重复组件)将如下所示.
Initially, the messages field (a Strapi repeatable component) will look like this.
"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"
}
]
我想向可重复组件添加另一条消息:
I want to add another message to the repeatable component:
"messages":[
{
"from": "user2",
"text": "happy hello world"
}
]
当我通过 curl 放置时:
When I Put it via curl:
curl -i -X PUT \
-H "Content-Type:application/json" \
-d \
'{
"messages":[
{
"from": "shop",
"text": "happy hello world"
}
]
}' \
'https://myserver/mes/5f781bdd23e08f001732cdd8'
它会覆盖之前的消息.如何在不丢失任何先前数据的情况下添加其他消息?
It overwrites the previous message. How do I add the other message without losing any previous data?
推荐答案
你必须像以前一样用 PUT 发送所有数组.
You have to send all the array with PUT like you did.
{
"id": "5f781bdd23e08f001732cdd8",
"messages": [
{
"id": "5f787348628eea0017b49f7e",
"from": "user1",
"text": "happy hello world"
},
{
"from": "shop",
"text": "happy hello world"
}
]
}
看起来 Strapi 不知道你是想更新第一个,还是删除它,或者创建一个新的......
Looks like Strapi can't know if you want to update the first, or delete it, or create a new one ...
这篇关于如何通过HTTP请求在trapi中添加可重复组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文