简体   繁体   English

使用 textInput 从用户获取值并分配给变量(React-Native)

[英]Getting value from user with textInput and assigning to variable (React-Native)

Here I want to assign the data from textInput to variable a.这里我想将来自 textInput 的数据分配给变量 a。 How can I do it?我该怎么做? (That is, when the user enters data in textInput, I want to assign it to variable a.) (即当用户在textInput中输入数据时,我想将其赋值给变量a。)

 import React, { Component } from 'react' import { Text, View, TextInput} from 'react-native' export default class deneme1 extends Component { constructor(props) { super(props); this.state = { a:"", }; } render() { return ( <View> <View style={styles.textinput}> <TextInput placeholderTextColor='white' style={styles.textinputtext} /> </View> </View> ) } }

You can try this one你可以试试这个

<TextInput
 placeholder={"A Variable"}
 onChangeText={(text) => this.setState({a: text}) }
 value={this.state.a}
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM