反应本机getall AsyncStorage并创建数组

时间:2018-07-19 09:19:28

标签: react-native

获取所有数据并在发送获取站点后创建数组 我该怎么办

[1]

1 个答案:

答案 0 :(得分:0)

async getAllData(){
  try {
    const keys = await AsyncStorage.getAllKeys();
    const stores = await AsyncStorage.multiGet(keys);
    return stores.map((store) => { return {[store[0]]: store[1]} })

  }catch (error) {
    console.log("ERROR", error);
    return []
  }  
}

调用方法

getAllData().then((response)=> {
  if(response.length){
    console.log(response)
    //Here you can call your API
   }else{
     console.log("NO RECORD FOUND")
   }
})