Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.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 未调用第二链API(React+;Axios)_Javascript_Reactjs_Axios - Fatal编程技术网

Javascript 未调用第二链API(React+;Axios)

Javascript 未调用第二链API(React+;Axios),javascript,reactjs,axios,Javascript,Reactjs,Axios,我正在尝试链接2个api调用,第一个是创建新服务的POST,第二个是使用正确的用户/管理员更新该服务的调用 然而,它从来没有进入api.updateUserRights export const addService = (service, user, rights) => (dispatch) => { const params = { name: service, disabled: false, rights: rights }; cons

我正在尝试链接2个api调用,第一个是创建新服务的POST,第二个是使用正确的用户/管理员更新该服务的调用

然而,它从来没有进入
api.updateUserRights

export const addService = (service, user, rights) => (dispatch) => {
  const params = {
    name: service,
    disabled: false,
    rights: rights
  };

  console.log('----------------- addService')
  console.log(' service', service)
  console.log(' user', user)
  console.log(' params', params)

  const addUserToService = (user) => api.updateUserRights(key, user);

  api.addService(service, params)
    // First Add the Service
    .then(res => {
      dispatch({
        type: actionTypes.ADD_SERVICE,
        payload: {
          service,
          rights
        }
      });
    })
    // Then Update the Admin to have the Service and Rights
    .then(addUserToService(user))
}

想法?这怎么可能被重写呢?

。然后
将函数作为参数,而不是函数调用。 尝试将链接的
更改为

    // Then Update the Admin to have the Service and Rights
.then(res => { addUserToService(user) } )

。然后
将函数作为参数,而不是函数调用。 尝试将链接的
更改为

    // Then Update the Admin to have the Service and Rights
.then(res => { addUserToService(user) } )

在这两个代码中都有两个名称为
addService
的代码。我不明白你的意思。很抱歉,糟糕的设计,
addService
是动作的创建者,但是
api.addService
是动作的创建者。addService
是api。你有两个代码,它们的名字都是
addService
。我不明白。对不起,糟糕的设计,
addService
是动作的创建者,但
api.addService
是api