我想我只需要另外一双眼睛,因为我无法得到我在这里缺少的东西。在服务器中,代码是:
function getByCategory (token, category) { return new Promise((res)
=> {
let posts = getData(token)
let keys = Object.keys(posts)
let filtered_keys = keys.filter(key => posts[key].category === category &&
!posts[key].deleted)
res(filtered_keys.map(key => posts[key])) }) }
在 postAPI 中,代码是:
export const getByCategory=(category)=>{
fetch(`${api}/${category}/posts`,{headers})
.then(res=>res.json())
.then(data=>data)
};
在类别中:
PostsAPI.getByCategory(category).then((posts) =>{
posts.map((post)=>{
return addPosts(post)
});
});
我的代码被推送到https://github.com/tulipjie/redux-readable我希望有人能帮助我。非常感谢。
你的方法不返回任何东西。尝试将“return”放在fetch前面,如下所示:
export const getByCategory=(category)=>{
return fetch(`${api}/${category}/posts`,{headers})
.then(res=>res.json())
.then(data=>data)
};
或者像这样删除花括号:
export const getByCategory=(category)=>
fetch(`${api}/${category}/posts`,{headers})
.then(res=>res.json())
.then(data=>data);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句