gpt4 book ai didi

angular - ionic 3 native 存储读取存储的值

转载 作者:搜寻专家 更新时间:2023-10-30 21:28:42 26 4
gpt4 key购买 nike

您好,

在我的代码中,我尝试了写在 Native Storage 插件页面上的代码:Native Storage

    import { NativeStorage } from '@ionic-native/native-storage';

constructor(private nativeStorage: NativeStorage) { }

...

this.nativeStorage.setItem('myitem', {property: 'value', anotherProperty: 'anotherValue'})
.then(
() => console.log('Stored item!'),
error => console.error('Error storing item', error)
);

this.nativeStorage.getItem('myitem')
.then(
data => console.log(data),
error => console.error(error)
);

当我启动我的 android 模拟器设备时,控制台会发回给我:

[00:02:01]  console.log: Stored item! 
[00:02:01] console.log: [object Object]

console

我想找到一个解决方案来读取存储的信息。因为我想使用存储在 native 存储中的值在外部页面上设置条件,但我不能。示例“如果存储在名称 Vibrator 的 native 存储中的值 == 为真,那么我们将启动此函数”。我正在寻找读取值的方法。你能帮帮我吗?

谢谢

最佳答案

要读取该值,请这样调用它:

console.log(data.property);
console.log(data.anotherProperty);

引用插件github可以更清楚的了解:https://github.com/TheCocoaProject/cordova-plugin-nativestorage

关于angular - ionic 3 native 存储读取存储的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47213258/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com