这是我的州的例子:
const INITIAL_STATE = {
contents: [ {}, {}, {}, etc.. ],
meta: {}
}
Run Code Online (Sandbox Code Playgroud)
我需要能够以某种方式替换内容数组中的项目,知道它的索引,我试过:
return {
...state,
contents: [
...state.contents[action.meta.index],
{
content_type: 7,
content_body: {
album_artwork_url: action.payload.data.album.images[1].url,
preview_url: action.payload.data.preview_url,
title: action.payload.data.name,
subtitle: action.payload.data.artists[0].name,
spotify_link: action.payload.data.external_urls.spotify
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
这里action.meta.index就是我想与其他内容对象来代替数组元素的索引,但我相信这只是代替整个数组这一个对象,我路过.我也想过使用.splice()但是这会改变数组吗?