arrays - 在 React Native 中显示数据数组中的值
问题描述
我从我的 API 中获取了这些数据。如何在文本输入中显示 name 属性的值?
[
{
"id": "1",
"userid": "",
"is_admin": "1",
"name": "Anshul Gupta",
"email": "testuser@gmail.com",
"company": "Kissui Metaliks and Steels Pvt. Ltd.",
"jobtitle": "Director",
"address": "366 and 368, MIE Part A, Bahadurgarh,Haryana,IndiaBahadurgarh, Haryana",
"cityid": "haryana",
"stateid": "Abohar",
...
}
]
解决方案
我不确定,但我想这就是你要找的:
import React, { Component } from 'react';
import { Text, View, TextInput } from 'react-native';
export default class HelloWorldApp extends Component {
constructor(props) {
super(props);
this.state = { dataSource:[]}
}
async componentDidMount(){
try {
AsyncStorage.getItem("user")
.then(async (user)=>{
const response = await fetch('myAPi=' + userData.id );
const responseJson = await response.json();
this.setState({ dataSource: responseJson})
})
}
}
render() {
return (
<View>
<Text>{this.state.dataSource[0]['name']}</Text>
<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
onChangeText={text => onChangeText(text)}
value={this.state.dataSource[0]['name']}
/>
<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
onChangeText={text => onChangeText(text)}
value={this.state.dataSource[0]['email']}
/>
</View>
);
}
}
推荐阅读
- amazon-web-services - 如何确定 Redis(已启用集群模式)复制组中的主端点
- ruby-on-rails-3 - Rails+simple_form_for 更改公共 id
- javascript - 为什么 Angular 会多次评估绑定表达式?
- python - 将字典列表转换为嵌套字典
- html - 页脚中的按钮在不同的页面长度上是不同的大小
- arrays - int(*p)[3]中的[3]是什么意思?
- amazon-web-services - aws lambda 为 http/1.1 返回 403
- treeview - 如何限制odoo中文本字段的字符(在树视图中显示)
- python - 将数据从一个 Excel 工作表复制到另一个工作表
- deep-learning - 我可以在 Colab 笔记本的驱动器上直接加载其他用户共享的数据吗?