Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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 返回(调度)未触发_Javascript_Api_Redux - Fatal编程技术网

Javascript 返回(调度)未触发

Javascript 返回(调度)未触发,javascript,api,redux,Javascript,Api,Redux,我是Redux的初学者,以下是我的代码: 组件:alerteProduit.js // Map Redux state to component props function mapStateToProps(state) { return { alertes: state.dashboardDomain.Qualite, //récupération de la liste contenu dans le state (dashboard_reducer -> Qualite)

我是Redux的初学者,以下是我的代码:

组件:alerteProduit.js

// Map Redux state to component props
function mapStateToProps(state) {
  return {
    alertes: state.dashboardDomain.Qualite, //récupération de la liste contenu dans le state (dashboard_reducer -> Qualite)
  }
}

// Map Redux actions to component props
function mapDispatchToProps(dispatch) {
  return {
    getAlertes: () => dashboard_actions.dashboard_getAlerteProduit(), //appel méthode action vers api
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(AlerteProduit);
export function dashboard_getAlerteProduit() { 
  console.log("fired")
  return (dispatch) => {
    console.log("not fired")
    var alertes = Deserialize(storage.get("alertes"))

    if (!alertes) {//si pas d'alertes dans le store local on va les chercher dans l'api
      dashboard_api.getAlerteProduits(dispatch, storage.get("1483")) //la fonction getAlerteProduits() attend l'id du client connecté
        .then((ap) => {
          storage.set("alertes", Serialize(ap))
          dispatch(Get_AlerteProduits(ap))
        })
    } else {//si on a déjà des alertes dans le store local on les renvois
      dispatch(Get_AlerteProduits(alertes))
    }
  };
}
export function getAlerteProduits(dispatch, idClient) {
    return auth_get_dispatch(dispatch, '/api/Produits/GetRappelProduit?idClient=' + idClient)
}
dashboard_action.js

// Map Redux state to component props
function mapStateToProps(state) {
  return {
    alertes: state.dashboardDomain.Qualite, //récupération de la liste contenu dans le state (dashboard_reducer -> Qualite)
  }
}

// Map Redux actions to component props
function mapDispatchToProps(dispatch) {
  return {
    getAlertes: () => dashboard_actions.dashboard_getAlerteProduit(), //appel méthode action vers api
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(AlerteProduit);
export function dashboard_getAlerteProduit() { 
  console.log("fired")
  return (dispatch) => {
    console.log("not fired")
    var alertes = Deserialize(storage.get("alertes"))

    if (!alertes) {//si pas d'alertes dans le store local on va les chercher dans l'api
      dashboard_api.getAlerteProduits(dispatch, storage.get("1483")) //la fonction getAlerteProduits() attend l'id du client connecté
        .then((ap) => {
          storage.set("alertes", Serialize(ap))
          dispatch(Get_AlerteProduits(ap))
        })
    } else {//si on a déjà des alertes dans le store local on les renvois
      dispatch(Get_AlerteProduits(alertes))
    }
  };
}
export function getAlerteProduits(dispatch, idClient) {
    return auth_get_dispatch(dispatch, '/api/Produits/GetRappelProduit?idClient=' + idClient)
}
dashboard_api.js

// Map Redux state to component props
function mapStateToProps(state) {
  return {
    alertes: state.dashboardDomain.Qualite, //récupération de la liste contenu dans le state (dashboard_reducer -> Qualite)
  }
}

// Map Redux actions to component props
function mapDispatchToProps(dispatch) {
  return {
    getAlertes: () => dashboard_actions.dashboard_getAlerteProduit(), //appel méthode action vers api
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(AlerteProduit);
export function dashboard_getAlerteProduit() { 
  console.log("fired")
  return (dispatch) => {
    console.log("not fired")
    var alertes = Deserialize(storage.get("alertes"))

    if (!alertes) {//si pas d'alertes dans le store local on va les chercher dans l'api
      dashboard_api.getAlerteProduits(dispatch, storage.get("1483")) //la fonction getAlerteProduits() attend l'id du client connecté
        .then((ap) => {
          storage.set("alertes", Serialize(ap))
          dispatch(Get_AlerteProduits(ap))
        })
    } else {//si on a déjà des alertes dans le store local on les renvois
      dispatch(Get_AlerteProduits(alertes))
    }
  };
}
export function getAlerteProduits(dispatch, idClient) {
    return auth_get_dispatch(dispatch, '/api/Produits/GetRappelProduit?idClient=' + idClient)
}
您可以在dashboard_action.js中看到,方法的开头被调用,但不是在“return”之后。你知道我的项目出了什么问题吗?顺便说一句,我的API返回了正确的结果,因此错误不是从这边来的。

我认为您的错误在mapDispatchToProps中

应该是:

getAlertes: () => dispatch(dashboard_actions.dashboard_getAlerteProduit())
更新:

此外,您还需要在dashboard_getAlerteProduit的arrow函数中返回:

if (!alertes) {//si pas d'alertes dans le store local on va les chercher dans l'api
  return dashboard_api.getAlerteProduits(dispatch, storage.get("1483")) //la fonction getAlerteProduits() attend l'id du client connecté
    .then((ap) => {
      storage.set("alertes", Serialize(ap))
      dispatch(Get_AlerteProduits(ap))
    })
} else {//si on a déjà des alertes dans le store local on les renvois
  return dispatch(Get_AlerteProduits(alertes))
}

您是否返回了带有“type”键的对象?@phobe更新了答案。