Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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 从阵列react redux thunk调度异步操作_Javascript_Reactjs_Redux_Async Await_Redux Thunk - Fatal编程技术网

Javascript 从阵列react redux thunk调度异步操作

Javascript 从阵列react redux thunk调度异步操作,javascript,reactjs,redux,async-await,redux-thunk,Javascript,Reactjs,Redux,Async Await,Redux Thunk,根据要求,我们需要从数组列表进行API调用。已使用redux thunk进行异步操作。API调用完成后,将请求参数传递给reducer时出现问题 # From the container let document = [ bankstatement1,bankstatement2]; document.map(element => { dispatch ( actions.uploadFiles(element) ) }); # insid

根据要求,我们需要从数组列表进行API调用。已使用redux thunk进行异步操作。API调用完成后,将请求参数传递给reducer时出现问题

    # From the container
    let document = [ bankstatement1,bankstatement2];
    document.map(element => {
     dispatch ( actions.uploadFiles(element) )
    });
    # inside actions
    export const uploadFiles = (payload) => {
      return async dispatch => {
        
        const response = await callAPIMiddleware(dispatch, {
          types: ['DOC_UPLOAD_START','DOC_UPLOAD_SUCCESS','DOC_UPLOAD_ERROR'],
          endPoint: ApiEndpoints.DOCUMENT_UPLOAD,
          type: HTTP_METHOD_TYPE.POST,
          payload: payload,
          headers: Headers.multipart,
          
        });
        return response;
      };
    };
    # inside axios middle ware
    export const callAPIMiddleware = async (dispatch, RequestParams) => {
     # calling upload_start ,here also the request payload being asked.     
        dispatch({
            type: "DOC_UPLOAD_START,
            data:RequestParams //bankstatement1,bankstatement2
          });
    
    # let res = await axios.post(endPoint,RequestParams, {
            headers: reqHeaders,
            config: reqConfig,
            });
    if (res && res.data) {
         
            dispatch({
              type:'DOC_UPLOAD_SUCCESS',
              data: res.data,
              param:RequestParams //bankstatement2,bankstatement2 here it is always referring to "bankstatement2" 
            });
    
    }
编辑: 如果你试着把最后一条逻辑放在“then”中,那么它肯定在那里

axios.post(endPoint,RequestParams, {
  headers: reqHeaders,
  config: reqConfig,
  }).then(res => {
    console.log('calling dispatch for ', RequestParams);
    if (res && res.data) {
      dispatch({
        type:'DOC_UPLOAD_SUCCESS',
        data: res.data,
        param: RequestParams,
      });
    } else {
      console.log('oops no result for ', RequestParams);
    }
  })
编辑: 如果你试着把最后一条逻辑放在“then”中,那么它肯定在那里

axios.post(endPoint,RequestParams, {
  headers: reqHeaders,
  config: reqConfig,
  }).then(res => {
    console.log('calling dispatch for ', RequestParams);
    if (res && res.data) {
      dispatch({
        type:'DOC_UPLOAD_SUCCESS',
        data: res.data,
        param: RequestParams,
      });
    } else {
      console.log('oops no result for ', RequestParams);
    }
  })

它仍在引用最后一个元素。不起作用。它仍在引用最后一个元素。不起作用。