gpt4 book ai didi

cordova - Phonegap : can't make localStorage persist

转载 作者:行者123 更新时间:2023-12-04 05:41:38 28 4
gpt4 key购买 nike

所以我初始化一切:

var Store = new Lawnchair({table:'mightapp', adaptor:'gears'}, 
function(s) {
var obj = {msg: 'hooray!'};

s.save({key: "msg", value: obj});
});

然后我注释掉消息以测试它是否仍然存在......
var Store = new Lawnchair({table:'mightapp', adaptor:'gears'}, 
function(s) {
//var obj = {msg: 'hooray!'};

//s.save({key: "msg", value: obj});
});

它没有 - 我做错了什么?我正在制作一个健身应用程序,我需要永久保存人们的锻炼/锻炼统计数据......我应该做一些文件输入/输出吗?

最佳答案

dom适配器对我来说很好用。这是我用来在应用程序重新启动时保留数据的代码。

<script type="text/javascript">
var store = new Lawnchair({
adapter: "dom",
name: "testing"
}, function(store) {
});

store.exists('dhaval', function(available){
var preStr = "";

// check whether required data is available, if not create it
if(available){
preStr = "data is already available, ";
}else{
preStr = "data is not available, ";
var me = {
key: 'dhaval'
};

// save it
store.save(me);
}

// access it later... even after app restart!
store.get('dhaval', function(me) {
$("#data").html(preStr + JSON.stringify(me));
});
});
</script>

对于完整的源代码检查 git repo android-cordova-lawnchair

关于cordova - Phonegap : can't make localStorage persist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11198403/

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