将数据保存在离线应用程序React Native中 [英] Keep data in offline app React Native
问题描述
我想使用React-Native离线为儿童创建一个字母应用程序,我想问一下什么是存储有关每个字母的数据的最佳方法,例如:字母ID,字母NAME,字母IMG_SRC等.考虑过使用JSON,但也决定询问您有关它的信息.也许有更好的方法.如果您与我分享自己的经验,我会很高兴)
I want to create offline an alphabet app for children using React-Native, and I want to ask you what is the best way to store data about each letter, for example: letter ID, letter NAME, letter IMG_SRC etc. I thought about using JSON, but as well decided to ask you about it. May be there's a better way. I'll be very happy if you share your own experience with me)
推荐答案
The easiest way to store offline data is using the AsyncStorage, it's basically a key value storage, super easy to use. You can save json in there or any other text, for example:
AsyncStorage.setItem('data', JSON.stringify([{id: 1, name: 'a', src: ''}]));
然后,以后,您可以像这样获取数据:
Then, later on, you can get that data like this:
AsyncStorage.getItem('data', (err, result) => {
console.log(JSON.parse(result));
});
对于简单的应用程序,这已经绰绰有余
For simple apps, this is more than enough
这篇关于将数据保存在离线应用程序React Native中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!