javascript - 我正在拨打我的 api 电话,但我无法将其返回给我的动作创建者
问题描述
我有一个动作创建者,它调用我的 apI(这是它自己的文件),api 工作,动作创建者也工作。我能够 console.log 来自 api 的响应,我的问题是将它返回给我的动作创建者,在那里进行了 api 函数调用。谢谢你。
**ACTION CREATOR**
import * as types from './actionTypes';
import FootballApi from '../api/footballApi';
import { loadLeag_Success } from '.';
//type
export const LOAD_LEAG_GAMES_SUCCESS = 'LEAGUE_GAMES_SUCCESS';
export function loadLeag_Game_Success(data){
//console.log("before dis", data);
return;
};
export function getLeaguesGames(idArr, date) {
return function(dispatch) {
Promise.all(FootballApi.getLeaguesGamesAPI(idArr, date))
.then(() => {
// . I WANT TO RETURN IT HERE.
console.log("returned")
})
// .catch(error => {
// throw(error)
// })
};
}
**API FILE**
export default class FootballApi {
static getAllLeags() {
return fetch('https://apifootball.com/api/?APIkey=42f53c25607596901bc6726d6d83c3ebf7376068ff89181d25a1bba477149480&action=get_leagues').then(response => {
return response.json();
}).catch(error => {
return error;
});
}
static getLeaguesGamesAPI(idArr, date){
return idArr.map((id)=>{
return fetch(`https://apifootball.com/api/?APIkey=42f53c25607596901bc6726d6d83c3ebf7376068ff89181d25a1bba477149480&action=get_events&from=${date}&to=${date}&league_id=${id}`)
.then(res =>{
return res.json();
})
.then((game) => {
if(!game.error){
//console.log("game")
return game;
}
})
})
}
};
解决方案
我想通了,我删除了-
.then((game) => {
if(!game.error){
//console.log("game")
}
})
并将其放入我的动作创建器中。一切都按我需要的方式工作。谢谢。
推荐阅读
- python - 到同一 DF 中最近点的距离
- pytorch - 当我尝试将 onnx 文件转换为 caffe2 时发生运算符翻译错误
- c++ - 如何找到添加两个变量的所有可能组合,每个变量都附加到一个乘数,总和为给定数字(cin)?
- c++ - 字符串比较中的意外输出
- javascript - 自定义密码要求的正则表达式
- listview - 如何在flutter的页面中添加listview和tabbarview
- angular - 我无法在角材料垫选择中填充保存的百分比值
- mysql - 对话属于多个用户,但用户 A 删除而用户 B 不删除。我们如何防止它被退回?
- java - SparkSql Aerospike Java 连接器
- java - 如何在 Spring Boot 中从资源服务器中的令牌中提取声明