Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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
Reactjs 我的redux thunk Axios调用返回我的redux存储中的空对象_Reactjs_Redux_React Redux_Redux Thunk - Fatal编程技术网

Reactjs 我的redux thunk Axios调用返回我的redux存储中的空对象

Reactjs 我的redux thunk Axios调用返回我的redux存储中的空对象,reactjs,redux,react-redux,redux-thunk,Reactjs,Redux,React Redux,Redux Thunk,我使用tmdb和redux thunk进行异步调用并返回数据。我尝试了所有可能的方法,只有空对象显示在我的存储中,即使当我记录结果时,我在那里看到了数据 我试图用地图标出结果,但运气不好。例如,如果我通过索引返回它(示例[0]),它会显示第一个索引的结果 商店和控制台的屏幕截图- 我希望商店显示结果,但只返回空对象。根据您的屏幕抓图,我希望您希望从ajax响应中发送数据。结果。现在你正在发送承诺 尝试使用console.log(top.data.results) 您的代码示例假设您的url列表将

我使用tmdb和redux thunk进行异步调用并返回数据。我尝试了所有可能的方法,只有空对象显示在我的存储中,即使当我记录结果时,我在那里看到了数据

我试图用地图标出结果,但运气不好。例如,如果我通过索引返回它(示例[0]),它会显示第一个索引的结果

商店和控制台的屏幕截图-


我希望商店显示结果,但只返回空对象。

根据您的屏幕抓图,我希望您希望从ajax响应中发送
数据。结果。现在你正在发送承诺

尝试使用
console.log(top.data.results)
您的代码示例假设您的url列表将只有4个数组项,因此您可以这样做:
axios.spread((顶部、弹出、弹出、现在)=>{
top
将是来自传递的第一个url的响应

调用api的代码笔可能会有所帮助


[您还在图像中公开api密钥]

您好,查看您的
getVideoKeys
功能可能会有所帮助,这是实际分派您的付费加载的位。添加的getVideoKeys功能基于您的图像,看起来您正在记录承诺。在分派之前,您可能需要“等待”结果。您知道
控制台的
top
类型。log
正在分派吗?Ye这是一个对象的类型。泰,改变了图片。
export const fetchVideoKeys = urlArray => {
  return dispatch => {
    dispatch(isLoading(true));
    axios
      .all(urlArray)
      .then(
        axios.spread((top, pop, up, now) => {
          console.log(top)
          dispatch(getVideoKeys(top));
        })
    );
  };
};
const initialState = {

    videoKeys: {
        topRated: [],
        popular: [],
        upcoming: [],
        nowPlaying: [],
    }
};


export default function VideoTrailerReducer(state=initialState, action) {
    switch (action.type) {
        case VideoTrailerActionTypes.GET_VIDEO_KEYS:
            return {
                videoKeys: {
                    topRated: [action.payload]
                }
            }

        default:
            return state;
    }
}
useEffect(() => {
    movieIds.popular.length > 1 &&
    movieIds.topRated.length > 1 &&
    movieIds.upcoming.length > 1 &&
    movieIds.nowPlaying.length > 1 &&
      setTimeout(() => {
        dispatch(
          fetchVideoKeys([
           createUrls(movieIds.topRated, videoUrls),
           createUrls(movieIds.popular, videoUrls),
           createUrls(movieIds.upcoming, videoUrls),
           createUrls(movieIds.nowPlaying, videoUrls)
          ])
        );
      }, 1000);
  }, [
    movieIds.topRated,
    movieIds.popular,
    movieIds.nowPlaying,
    movieIds.upcoming
  ]);
export const getVideoKeys = data => {
    return {
        type: VideoTrailerActionTypes.GET_VIDEO_KEYS,
        payload: data
    }
 }