【问题标题】:Getting value from user with textInput and assigning to variable (React-Native)使用 textInput 从用户获取价值并分配给变量(React-Native)
【发布时间】:2020-12-23 12:54:26
【问题描述】:

在这里,我想将 textInput 中的数据分配给变量 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>
        )
    }
}

【问题讨论】:

    标签: javascript android ios react-native


    【解决方案1】:

    你可以试试这个

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-19
      • 1970-01-01
      • 1970-01-01
      • 2019-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多