react-native - 试图从同一页面中的多个 api React native 获取结果
问题描述
我试图从数据库中获取数据并将其放入选择器中,当我使用一个 fecth 时它工作正常,但是当我添加第二个时,它得到一个错误提示“typeError: undefined is not an object (evalating 'this.state.dataSource2.地图') ”
componentDidMount() {
fetch('url1')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource: responseJson,
}
);
})
.then( () => {
fetch('url2')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource2: responseJson
});
})
})
.catch((error) => {
console.error(error);
});
}
第一个选择器:
onValueChange={(itemValue, itemIndex) => this.setState({ar1: itemValue})} >
{ this.state.dataSource.map((item, key)=>(
<Picker.Item label={item.nom} value={item.nom} key={key} />)
)}
</Picker>
第二个选择器:
onValueChange={(itemValue, itemIndex) => this.setState({ar2: itemValue})} >
{ this.state.dataSource2.map((item, key)=>(
<Picker.Item label={item.nom} value={item.nom} key={key} />)
)}
</Picker>
解决方案
推荐阅读
- git - 如何 git 撤消合并文件
- c# - 程序在没有任何东西的情况下关闭 C#
- html - Flex如何显示保持垂直对齐的项目表
- regex - 尝试匹配以 ly 结尾但不是比较/最高级形式的副词
- drop-down-menu - 如何将下拉按钮中的列表大小固定为数字并使其在颤动中可滚动?
- java - Observer - 围绕电子邮件接收逻辑的可观察模型
- json - 从 JSON 检索值到经典 ASP
- angular - 有没有办法在 Angular 7 中命名路线?
- mysql - UNION ALL LEFT JOIN 和 SUM 返回不正确的值
- selenium - 使用无头时 Selenium 数据目录出错