我正在使用 JavaScript 制作 Android PhoneGap 应用程序。
应用程序从本地文本文件加载数据并将其存储在本地存储中,然后从本地存储加载数据。
当我想要更新文本文件中的数据并让应用程序再次将数据重新加载到本地存储中时,问题就出现了。我无法让它加载文本文件一次,然后再也不会。每次应用程序启动时,它都会再次加载文本文件,直到我进行另一次更新设置 localStorage.update = 0;
这是我尝试过的代码,但得到了上述结果。
localStorage.update = 1; //tell the app to update
//but this will run each time the app is opened
if(localStorage.update == 1) {
localStorage["StoredData"] = ""; //text file data is stored in [StoredData]
//Proceed to load the text file into storage
localStorage.update = 0;
}
谢谢。
最佳答案
事实证明以下代码有效:
if(localStorage.update == 1) { // change this value everytime you want to reload the file
localStorage["StoredData"] = ""; //text file data is stored in [StoredData]
//Proceed to load the text file into storage
localStorage.update = 1; //set this to the same as the if statement
}
关于javascript - Android 应用程序 - 运行 JavaScript 函数一次,然后在应用程序更新之前不再运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15883256/