【问题标题】:How to redirect to another screen after adding asyncstorage data添加异步存储数据后如何重定向到另一个屏幕
【发布时间】:2021-12-12 12:51:39
【问题描述】:

我是本机反应的新手,试图在相同的按钮按下事件上重定向和添加数据。我尝试在等待操作后使用 .then ,但无法正常工作 要么是添加数据,要么是重定向——不知道如何将两者结合起来?

   <Button title="Add now !" 
            onPress={ ()=> addtoStorage(initname, initclas, initsubject) }

 addtoStorage = async(par1, par2, par3) =>{
       
        try{
            
            let makeObject = {name:par1, class:par2, subject:par3, 
                              id: Increase.key.toString()};
             console.log(makeObject);
             await AsyncStorage
               .setItem( makeObject.id , JSON.stringify(makeObject) )
             .then(Increase())
             .then(moveAround.navigate(first)); //not working here
        } catch(e){

        }
       console.log('done');
      }

【问题讨论】:

    标签: react-native button react-navigation hybrid-mobile-app asyncstorage


    【解决方案1】:

    终于解决了,不需要.then语句

    我刚刚做了 setItem(分号),然后移动到第一个或所需的屏幕。

       await AsyncStorage.setItem(makeObject.id , JSON.stringify(makeObject));
        moveAround.navigate('first');

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多