Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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
Redux 使用数组将推送到第二级对象_Redux_Immutable.js - Fatal编程技术网

Redux 使用数组将推送到第二级对象

Redux 使用数组将推送到第二级对象,redux,immutable.js,Redux,Immutable.js,我有一个redux商店,看起来像这样: posts : { posts: [ 0: { }, 1: { } ] } case LOAD_MORE_POSTS_SUCCESS: return { ...state, posts: [...state.posts, action.posts], isFetching: false, } case LOAD_MORE_POSTS_SUCCESS: return { ..

我有一个redux商店,看起来像这样:

posts : {
   posts: [
      0: { },
      1: { }
   ]
}
case LOAD_MORE_POSTS_SUCCESS:
  return {
    ...state,
    posts: [...state.posts, action.posts],
    isFetching: false,
  }
case LOAD_MORE_POSTS_SUCCESS:
  return {
    ...state,
    posts: [...state.posts, ...action.posts],
    isFetching: false,
  }
我想在数组中添加以下额外项:

posts : {
   posts: [
      0: { },
      1: { }
   ]
}
case LOAD_MORE_POSTS_SUCCESS:
  return {
    ...state,
    posts: [...state.posts, action.posts],
    isFetching: false,
  }
case LOAD_MORE_POSTS_SUCCESS:
  return {
    ...state,
    posts: [...state.posts, ...action.posts],
    isFetching: false,
  }
然而,这只是把额外的职位推到了第一级,我尝试过这样做(运气不好):


你有没有试过这样的方法:

case LOAD_MORE_POSTS_SUCCESS:
  return {
    ...state,
    posts: {
      posts: [...state.posts.posts, action.posts]
    },
    isFetching: false,
  }

和如果<代码> Actudio。POST <代码>是一个数组(复数形式暗示它是),考虑使用:

posts: {
  posts: [...state.posts.posts, ...action.posts]
}

感谢@Gila Artzi-我的最终代码如下所示:

posts : {
   posts: [
      0: { },
      1: { }
   ]
}
case LOAD_MORE_POSTS_SUCCESS:
  return {
    ...state,
    posts: [...state.posts, action.posts],
    isFetching: false,
  }
case LOAD_MORE_POSTS_SUCCESS:
  return {
    ...state,
    posts: [...state.posts, ...action.posts],
    isFetching: false,
  }

非常感谢-我需要包括操作的spread操作符:…action.posts。