如何获取本机脚本本地存储中的所有密钥

时间:2018-10-15 13:39:34

标签: angular nativescript

我创建了一个有角度的本机脚本项目,并且正在使用“ nativescript-localstorage”。我想获取存储中的所有密钥,我该怎么做

4 个答案:

答案 0 :(得分:2)

您可以遍历所有localStorage项,并使用localStorage.key(index)来获取密钥,并在localStorage.getItem中使用它来获取值。

for (let i = 0; i < localStorage.length; i++) {
    let key = localStorage.key(i);
    let val = localStorage.getItem(key);
}

答案 1 :(得分:0)

您可以使用localStorage

创建条目

let key = 'Item 1';
localStorage.setItem(key, 'Value');

阅读条目

let myItem = localStorage.getItem(key);

更新条目

localStorage.setItem(key, 'New Value');

删除条目

localStorage.removeItem(key);

清除所有内容

localStorage.clear();

答案 2 :(得分:0)

您需要使用本地存储。length将返回存储的密钥数。

console.log("Keys stored", localStorage.length);

您还可以迭代存储在本地存储中的所有密钥 localstorage.key返回此位置的密钥名称

for (let i = 0; i < localStorage.length; i++) {
    let key = localStorage.key(i); // Will return the name of the key
    let val = localStorage.getItem(key); // will return the value
}

答案 3 :(得分:0)

获取本地存储密钥的长度。 返回存储的键数

  

localStorage.length

在此位置返回密钥名称

  

localStorage.key(id)

org.apache.spark.SparkException: Job aborted due to stage failure: Task 2 in stage 2.0 failed 4 times, most recent failure: Lost task 2.3 in stage 2.0 (TID 141, wn4-novakv.oetevw42cdoe3jls1dzdeclktg.ex.internal.cloudapp.net, executor 2): java.io.IOException: Cannot run program "/mnt/resource/hadoop/yarn/local/usercache/livy/appcache/application_1539905356890_0003/spark-5da59a08-a6a4-443d-b3b1-c31643e195c5/userFiles-e3ca8a1b-44f6-4804-9c95-625b1742fb77/print.py": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at org.apache.spark.rdd.PipedRDD.compute(PipedRDD.scala:111)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)
    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
    at org.apache.spark.scheduler.Task.run(Task.scala:109)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:345)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: error=2, No such file or directory