I am using JSON server to create a simple API.
(我正在使用JSON服务器创建一个简单的API。)
I would like to update a nested array in this case the videos array in the playlist with id 'default':(我想在这种情况下更新播放列表中ID为'default'的视频数组的嵌套数组:)
"playlists": [
{
"id": "default",
"videos": [
{
"id": 123
},
{
"id": 456
}
]
}
]
My understanding is that the PATCH specification defines the following operations:
(我的理解是PATCH规范定义了以下操作:)
Add - Adds a value to an object or inserts it into an array
(添加-向对象添加值或将其插入数组)
Following this example :
(下面的例子 :)
{ "op": "add", "path": "/biscuits/1", "value": { "name": "Ginger Nut" } }
My request looks like this:
(我的要求看起来像这样:)
axios.patch('http://localhost:3000/playlists/default', {
op: 'add',
path: '/videos',
value: {"id":789}
});
However this request simply adds the values to the 'default' playlist, without modifying the 'videos' array:
(但是,此请求只是将值添加到“默认”播放列表中,而无需修改“视频”数组:)
"playlists": [{
"id": "default",
"videos": [
{
"id": 123
},
{
"id": 456
}
],
"op": "add",
"path": "/videos",
"value": "test"
}]
My question is whether there is an easy way to update a nested array using a PATCH request with json-server?
(我的问题是,是否有一种简单的方法可以通过使用带有json-server的PATCH请求来更新嵌套数组?)
ask by ogot translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…