【发布时间】:2019-03-18 16:39:18
【问题描述】:
这是我的 JSON 文件
{
"name": "Thịt bò",
"noed": 5
},
{
"name": "Thịt heo",
"noed": 3
}
我让他们加入 Flatlist
<FlatList
data={cats}
keyExtractor={item => item.name}
renderItem={({item})=>(
<View>
<Text style={styles.catsItem} onPress={() => this.changeTextInput(item.name)}>{item.name} {item.noed}</Text>
</View>
)}
/>
但我想发送两个值是 item.name 和 item.noed 到 TextInput 然后将它们发送到另一个屏幕
changeTextInput(item){
this.setState({name: item});
};
但我不知道如何将item.noed 发送到 TextInput 以及如何将它们发送到另一个屏幕。
我是新手,请帮帮我。
【问题讨论】:
-
你在用
react-navigation吗? -
您基本上想将用户键入的输入值存储到组件状态。查看文档:facebook.github.io/react-native/docs/textinput
onChangeText={(text) => this.setState({text})}。要调试,请在渲染中记录状态以查看它是否真的保存到您的状态 `render() { console.log(this.state); returnthis.props.navigation.navigate("MyNextScreen", { userInput: this.state });
标签: react-native react-native-flatlist