Javascript 参数化异步函数返回承诺{quot;'U 40";:0,'U 55";:“English";,“U 65";:1,'U 72";:null,}

Javascript 参数化异步函数返回承诺{quot;'U 40";:0,'U 55";:“English";,“U 65";:1,'U 72";:null,},javascript,reactjs,function,react-native,async-await,Javascript,Reactjs,Function,React Native,Async Await,[闭门] 如何从不必要的承诺对象中去掉“英语” 异步函数->参数化 const getLanguageNamefromCode=异步(lng\U代码)=>{ 让响应,langData,lang; 试一试{ 响应=等待获取( `https://restcountries.eu/rest/v2/lang/${lng_code}?字段=语言` ); langData=wait response.json(); //console.log(langData[0].languages[0]); if(l

[闭门] 如何从不必要的承诺对象中去掉“英语”

异步函数->参数化


const getLanguageNamefromCode=异步(lng\U代码)=>{
让响应,langData,lang;
试一试{
响应=等待获取(
`https://restcountries.eu/rest/v2/lang/${lng_code}?字段=语言`
);
langData=wait response.json();
//console.log(langData[0].languages[0]);
if(langData[0]。语言[0]。iso639_1==lng_代码){
lang=langData[0]。语言[0]。名称;
console.log(lang);
}
还郎;
}捕捉(错误){
抛出新错误(err);
}
};
从for循环内部调用它并发送参数

const-loadedTrendingMovies=[];
const loadedTrendingMoviesLength=trendingMovies.results.length;
for(设i=0;i<6;i++){
//让学分;
hasUserSaved=getState().UserMovies.UserMovies.find(
(userMovie)=>
userMovie.id==trendingMovies.results[i].id.toString()
);
loadedTrendingMovies.push(
新电影(
trendingMovies.results[i].id.toString(),
trendingMovies.results[i]。媒体类型==“电影”
?trendingMovies.结果[i].标题
:trendingMovies.results[i].名称,
posterBaseUrl+trendingMovies.results[i].poster_路径,
trendingMovies.results[i]。媒体类型==“电影”
?trendingMovies.results[i].发布日期
:trendingMovies.results[i].第一次播放日期,
[],
trendingMovies.结果[i].概述,
趋势电影。结果[i]。平均投票,
getLanguageNamefromCode(trendingMovies.results[i].原始语言),
hasUserSaved?hasUserSaved.location:“
)
);
}
如何从getLanguagefromCode异步方法返回的承诺中获取值

这是我的MoviesScreen功能组件,我正在使用redux

import React,{useffect,useCallback,useState,useRef}来自“React”;
进口{
看法
文本,
样式表,
平面列表,
滚动视图,
状态栏,
可触摸且无反馈,
刷新控制,
}从“反应本族语”;
从“@expo/vector icons”导入{Ionicons}”;
从“./components/MovieItem”导入电影项目;
从“react-redux”导入{useSelector,useDispatch};
从“./store/actions/MoviesAction”导入*作为MoviesAction;
从“./store/actions/UserActions”导入*作为用户操作;
从“./常量/颜色”导入颜色;
从“@react navigation/native”导入{useCollToTop}”;
从“反应本机骨架内容”导入骨架内容;
从“重新选择”导入{createSelector};
const stories=createSelector(
(州)=>state.Movies.Movies,
(电影)=>电影
);
const newReleases=createSelector(
(state)=>state.Movies.new_发布,
(新发布)=>新发布
);
const newTVShows=createSelector(
(州)=>state.Movies.new_tv_节目,
(新电视节目)=>新电视节目
);
const Anime=createSelector(
(state)=>state.Movies.anime,
(动画)=>动画
);
常量电影屏幕=(道具)=>{
常量故事=使用选择器(故事);
const new_releases=使用选择器(newReleases);
日志(“电影屏幕渲染”,新发布);
const new_tv_shows=使用选择器(newTVShows);
常量动画=使用选择器(动画);
const[loading,setLoading]=useState(false);
const[refreshing,setRefreshing]=useState(false);
const dispatch=usedpatch();
常量scrollRef=useRef(null);
使用ScrollToTop(scrollRef);
const onRefresh=useCallback(()=>{
设置刷新(真);
loadScreen()。然后(()=>setRefreshing(false));
},[setRefreshing,loadScreen]);
const loadScreen=useCallback(异步()=>{
试一试{
分派(MoviesAction.loadAll());
}捕捉(错误){
控制台日志(err);
}
}, []);
useffect(()=>{
设置加载(真);
loadScreen()。然后(()=>setLoading(false));
}, []);
const renderTrendingMoviesItem=({item})=>(
{
props.navigation.navigate({
名称:“MoviesDetailScreen”,
参数:{
电影id:item.id,
电影名称:item.title,
电影类型:“电影”,
},
});
}}
/>
);
常量renderStorieItem=({item})=>(
{
props.navigation.navigate({
名称:“NewReleaseModalScreen”,
参数:{
电影名称:item.title,
posterUrl:item.posterUrl,
电影id:item.id,
},
});
}}
/>
);
常量renderTrendingVitem=({item})=>(
{
props.navigation.navigate({
名称:“MoviesDetailScreen”,
参数:{
电影id:item.id,
电影名称:item.title,
电影类型:“电视”,
},
});
}}
/>
);
常量renderAnimeItem=({item})=>(
{
props.navigation.navigate({
名称:“MoviesDetailScreen”,
参数:{
电影id:item.id,
电影名称:item.title,
电影类型:“动画”,
戈托尼姆:是的,
},
});
}}
/>
);
返回(
{/*新发布的故事*/}
新版本
项目id}
showshorizontalscrolindicator={false}
水平={true}
数据={Stories}
renderItem={RenderStorieItem}
/>
{/*新发布的故事*/}
{/*...
那周的热门电影
...
*/}
{
导航道具
loadedTrendingMovies Array [
  Movie {
    "cast": Array [],
    "id": "385103",
    "language": "English",
    "location": "",
    "plot": "In Scooby-Doo’s greatest adventure yet, see the never-before told story of how lifelong friends Scooby and Shaggy first met and how they joined forces with young detectives Fred, Velma, and Daphne to form the famous Mystery Inc. Now, with hundreds of cases solved, Scooby and the gang face their biggest, toughest mystery ever: an evil plot to unleash the ghost dog Cerberus upon the world. As they race to stop this global “dogpocalypse,” the gang discovers that Scooby has a secret legacy and an epic destiny greater than anyone ever imagined.",
    "posterUrl": "http://image.tmdb.org/t/p/w185/zG2l9Svw4PTldWJAzC171Y3d6G8.jpg",
    "ratings": 8.3,
    "title": "Scoob!",
    "year": "2020-05-15",
  },
  Movie {
    "cast": Array [],
    "id": "79680",
    "language": "English",
    "location": "",
    "plot": "Set more than seven years after the world has become a frozen wasteland, the remnants of humanity inhabit a gigantic, perpetually-moving train that circles the globe as class warfare, social injustice and the politics of survival play out.",
    "posterUrl": "http://image.tmdb.org/t/p/w185/n6UNHZoiYj81abwmG38HbNjflDx.jpg",
    "ratings": 3,
    "title": "Snowpiercer",
    "year": "2020-05-17",
  },
  Movie {
    "cast": Array [],
    "id": "80986",
    "language": "English",
    "location": "",
    "plot": "Courtney Whitmore, a smart, athletic and above all else kind girl, discovers her step-father has a secret; he used to be the sidekick to a superhero. \"Borrowing\" the long-lost hero’s cosmic staff, she becomes the unlikely inspiration for an entirely new generation of superheroes.",
    "posterUrl": "http://image.tmdb.org/t/p/w185/JJxVsQPPiuLcArALotMHsCubeo.jpg",
    "ratings": 9,
    "title": "Stargirl",
    "year": "2020-05-18",
  },
  Movie {
    "cast": Array [],
    "id": "530915",
    "language": "English",
    "location": "",
    "plot": "At the height of the First World War, two young British soldiers must cross enemy territory and deliver a message that will stop a deadly attack on hundreds of soldiers.",
    "posterUrl": "http://image.tmdb.org/t/p/w185/AuGiPiGMYMkSosOJ3BQjDEAiwtO.jpg",
    "ratings": 7.9,
    "title": "1917",
    "year": "2019-12-25",
  },
  Movie {
    "cast": Array [],
    "id": "582596",
    "language": "English",
    "location": "",
    "plot": "A guy meets the woman of his dreams and invites her to his company's corporate retreat, but realizes he sent the invite to the wrong person.",
    "posterUrl": "http://image.tmdb.org/t/p/w185/A2YlIrzypvhS3vTFMcDkG3xLvac.jpg",
    "ratings": 6.1,
    "title": "The Wrong Missy",
    "year": "2020-05-13",
  },
]
 movie screen rendered Array []
 movie screen rendered Array []
 movie screen rendered Array []
 movie screen rendered Array []