Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript reducer状态更改后缺少嵌套对象_Javascript_Reactjs_Redux - Fatal编程技术网

Javascript reducer状态更改后缺少嵌套对象

Javascript reducer状态更改后缺少嵌套对象,javascript,reactjs,redux,Javascript,Reactjs,Redux,我正试图在我的状态下更新selectedAnswer: case "SET_ANSWER": { const { selectedAnswer, id } = action.data; return { videos: state.videos.map(video => video.id === id ? { ...video, selectedAnswer } : video ), search: { term: "", videos: []

我正试图在我的状态下更新
selectedAnswer

case "SET_ANSWER": {
  const { selectedAnswer, id } = action.data;

  return {
    videos: state.videos.map(video =>
      video.id === id ? { ...video, selectedAnswer } : video
    ),
    search: { term: "", videos: [] }
  };
}
我的原始状态如下所示:

videos: [{
bookMarked: false
completed: false
current: 0
description: "ffff"
icon: "administrating-vaccinations"
id: 138
parentId: ""
preview: "ddd"
questions: [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
recapId: "374"
results: {correctAnswers: Array(0), incorrectAnswers: Array(0), totalScore: 0}
selectedAnswer: ""
title: "ddd"
youtubeVideo: "ddd"
}...]
但是,在我的reducer更新状态后,我得到了未定义的
结果

...
questions: (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
recapId: "374"
results: undefined <<<<<<
selectedAnswer: ""
title: "Administering Vaccinations"
youtubeVideo: "P2ZSmFDODG4"

spread运营商不做深度克隆,你必须做

videos: state.videos.map(video =>
      video.id === id ? { ...video, results: {...video.results}, selectedAnswer } : video
    ),

你的答案是,不要告诉我你的问题。你能创建沙盒吗也许你应该从map方法返回,-也许你有typeo
videos: state.videos.map(video =>
      video.id === id ? { ...video, results: {...video.results}, selectedAnswer } : video
    ),