React native 使用react native中的下拉列表绑定API数据
我正在react native中构建一个示例应用程序,其中需要在下拉列表中显示使用for loop的API数据。它在console.log()中显示数据,但有错误,也没有显示数据,没有手机 下面是代码文件React native 使用react native中的下拉列表绑定API数据,react-native,React Native,我正在react native中构建一个示例应用程序,其中需要在下拉列表中显示使用for loop的API数据。它在console.log()中显示数据,但有错误,也没有显示数据,没有手机 下面是代码文件 for(i=0; i<=this.state.droparray.length;i++) { var str_Code=this.state.droparray[i].Code console.log
for(i=0; i<=this.state.droparray.length;i++)
{
var str_Code=this.state.droparray[i].Code
console.log('Code agya h+++++++ ', str_Code)
}
<DropDownPicker
items={[
{ label: 'ABC-12345678901',Code: 'PP-12345678901', },
{ label: 'ABC-12345678902',Code: 'PP-12345678902', },
{ label: 'ABC-12345678903',Code: 'PP-12345678903', },
{ label: 'ABC-12345678904',Code: 'PP-12345678904', },
{ label: 'ABC-12345678905',Code: 'PP-12345678905', },
]}
// defaultValue={this.state.item}
containerStyle={{ height: '20%'}}
placeholder="Select A Numbers"
style={{ backgroundColor: 'white' }}
itemStyle={{
justifyContent: 'flex-start',
}}
dropDownStyle={{ backgroundColor: 'transparent' }}
onChangeItem={item => this.setState({
Code: item.Code
})}
/>
</View>
(i=0;i)的
有什么解决办法吗?试试下面的方法
state = {
droparray: [];
}
async componentDidMount() {
try {
const droparray = await fetch('https://example.com/');
// example like [{name: "John"},{name: "William"}];
var res = [];
droparray.map((item) {
res.push({...item, label: item.name});
// this process is for DropDownPicker as required label in data
});
this.setState({droparray: res});
} catch(err) {
console.log("Error fetching data-----------", err);
}
}
<View>
<DropDownPicker
items={this.state.droparray} // Do something like so it will reflect on view
.......
/>
</View>
状态={
droparray:[];
}
异步组件didmount(){
试一试{
const droparray=等待提取('https://example.com/');
//例如[{name:John},{name:William}];
var-res=[];
droparray.map((项){
res.push({…项,标签:item.name});
//此过程适用于数据标签中所需的DropDownPicker
});
this.setState({droparray:res});
}捕捉(错误){
log(“获取数据时出错------------”,err);
}
}