【问题标题】:Set Text In TextInput react-native在 TextInput 中设置文本 react-native
【发布时间】:2018-01-29 18:05:43
【问题描述】:

有什么方法可以重新设置 react-native 的 textinput 中的文本值吗? 如下所示,这是我正在做的: 我想在 textinput 中设置我的超级翻译文本值。我该怎么做?

   <TextInput 
         style={{color:'black',width:width-60, borderColor: 'black'}}
         placeholder="Ask your Question ?"
         underlineColorAndroid='black'
         autoCapitalize="words"
         placeholderTextColor="black"
         keyboardType = "default"
         error = {this.state.errpwd}
         onBlur={() => this.setState({errpwd:""})}
         onChangeText={ (questionText) => this.setState({input: questionText}) }/>      

          <View style={styles.section}>
                <PowerTranslator style={styles.p} text={'user input: ' + this.state.input} />
            </View>

【问题讨论】:

    标签: react-native


    【解决方案1】:

    将 value 属性添加到您的 TextInput

    value={this.state.input}
    

    【讨论】:

    • 您能否更具体地说明您想要实现的目标?
    • 我正在使用谷歌翻译 API,为此我正在使用 npm 电源翻译器。基本上,我的目标是,当用户在 textinput 上输入一些输入时,它会自动翻译,所以我会这样做这种类型的东西,我使用电源翻译器翻译我的输入,但现在我想将我翻译的文本设置为 textinput
    • 您希望高级翻译器的响应反映在您的文本输入中吗?
    • 这是一项棘手的任务。您需要在每个空格之后在文本输入中拆分您的值,选择从拆分获得的数组中的最后一项,将其发送到翻译服务器,等待响应,将响应设置为数组的最后一项,替换旧的,并将该值分配给文本输入。我知道这是一个模糊的答复,但是一个方向。您需要使用 javascript 方法和运算符,如 split、spread 等来实现这一点。
    猜你喜欢
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 2019-07-09
    • 2018-11-23
    • 2018-12-01
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    相关资源
    最近更新 更多