bdr*_*oid 3 javascript reactjs react-native
我想要得到的是选择“质量”的“url”值是 hd720
成分
componentDidMount() {
return fetch('https://you-link.herokuapp.com/?url=https://www.youtube.com/watch?v=YGCLs9Bt_KY')
.then((响应) => response.json())
.then((responseJson) => {
this.setState({
isLoading: 假,
数据源:responseJson,
视频网址:responseJson[0].url
}, 功能() {
});
})
.catch((错误) => {
控制台错误(错误);
});
}
Json 调用
链接
在这种情况下,您只需要使用匹配条件(使用 find)搜索 JSON 数组“质量”===“hd720”
componentDidMount() {
return fetch('https://you-link.herokuapp.com/?url=https://www.youtube.com/watch?v=YGCLs9Bt_KY')
.then((response) => response.json())
.then((responseJson) => {
let url = responseJson.find(obj => obj.quality === "hd720").url
this.setState({
isLoading: false,
dataSource: responseJson,
videoUrl: url
}, function() {});
})
.catch((error) => {
console.error(error);
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1280 次 |
| 最近记录: |