React(redux),如何将列表中的列表作为分离项推送

React(redux), how to push list in list as saparated items

我想将列表中的项目推送到先前状态的列表中。 我使用了不可变 "List" 和 list.push() 但是,它不会推送分离的项目。

只是整个列表都处于以前的列表状态。像这样。

列表 [(1), (2), (3)] + 列表 [(1), (2)]

==> 列表 [(1), (2), (3), 列表[(1) (2)]]

我想获取列表 [(1), (2), (3), (4), (5)]

下面推送列表Reducer

  ...pender({
    type: PATCH_IMG,
    onSuccess: (state, action) => {
      const images = List(state.getIn(['orderById', 'images']))
      return state.setIn(['orderById', 'images'], images.push(List(action.payload.data)))
    }

return payload.data 下面是 fileList (server-Nodejs)

router.patch('/img/:id', upload.array('images', 10), async(req, res) => {
  let fileList = [];
  for(let i = 0; i < req.files.length; i++) {
    fileList.push(`/img/${req.files[i].filename}`)
  }
  const order = await Order.findByIdAndUpdate(
    req.params.id,
    {
      $push: {"images": fileList}
    }
  )
  await res.send(fileList);
})

这是执行reducer之前的截图(下图link)。

enter image description here

这是执行reducer后的截图(下图link)。

enter image description here

因为你是将数组推入数组。

在你的情况下你应该使用concat来合并数组

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat

例如: images.concat(List(action.payload.data))