我发现tns-core-modules/application-settings
能够在设备上存储数据。我有一个应用程序,我想将用户的收藏夹存储到设备中。
假设我存储了一个最喜欢的歌曲列表,我可以使用setString
和getString
,但我不确定如何通过编程来获得所有歌曲。有没有其他我缺少的选项或方法来实现这一点,其中可以使用songs
作为密钥访问dict,并且可以加载所有songs
?
将JSON.stringify
与setString
/JSON.parse
与getString
一起使用。
// Set favorite songs
appSettings.setString("favorites", JSON.stringify(songs));
// Get favorite songs
const songs = JSON.parse(appSettings.getString("favorites", "{}"));