首页 > 解决方案 > 我怎样才能发送我的输入值通过 onSubmitEditing 到异步函数?

问题描述

我想在本机反应中保存字段输入的值。如何使用onSubmitediting事件将值发送到异步函数?

我试过这个:

<TextInput onSubmitEditing={ (text) => this.Store(text)}></TextInput>

这是我正在使用的功能

Store = async() =>
{
    var textvalue = "here the value of the <TextInput>";
    try 
    {
        await AsyncStorage.setItem('@Temp:city', textvalue );
    } 
    catch (error) 
    {
        console.log(error)
    }
}

标签: react-native

解决方案


Please try this:

   <TextInput 
     onSubmitEditing={ event => {
      const text = event.nativeEvent.text;
      this.Store(text);
    }} >
   </TextInput>

And save like this:

Store = async(text) => {
     try 
     {
     await AsyncStorage.setItem('@Temp:city', text );

     } 
     catch (error) 
     {
      console.log(error)
     }
 }

推荐阅读