typescript - 在 nativescript 应用程序设置中存储一组收藏夹

标签 typescript nativescript angular2-nativescript

我看到tns-core-modules/application-settings能够在设备上存储数据。我有一个应用程序,我想将用户的收藏夹存储到设备上。

假设我正在存储最喜欢的歌曲列表,我可以使用 setStringgetString,但我不确定如何以编程方式完成此操作来获取所有歌曲。是否有另一种选项或方法来实现我所缺少的,可以使用歌曲作为键来访问字典,并且可以加载所有歌曲

最佳答案

使用 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", "{}"));

关于typescript - 在 nativescript 应用程序设置中存储一组收藏夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53543405/

相关文章:

android - 您使用 NativeScript 的体验如何?

nativescript - tns 预览对意外 token 不起作用

nativescript - 如何在 NativeScript 中设置正确的资源路径?

NativeScript:toggleDrawerState 不是函数错误

Angular 5 在运行时使用 Angular CLI 加载语言环境

javascript - 如何以类和方法格式定义 typescript/Oracledb npm 连接?

javascript - react 路由器 typescript 错误

javascript - 有一个可变的 templateUrl

nativescript - 在 NativeScript 和 Angular2 中传递环境相关变量

typescript - 在 TypeORM 和 MySQL 中返回插入查询的 ID