【问题标题】:Lawnchair + Android + PhoneGap working, but not persistentLawnchair + Android + PhoneGap 工作,但不持久
【发布时间】:2013-05-14 04:23:59
【问题描述】:

这是我第一次尝试使用Lawnchair。我能够得到一个简单的保存/获取示例,但只要它在同一个应用程序启动中,get 似乎只能工作。在随后的应用启动时,它无法找到我之前保存的对象,因此它似乎不是持久的。

我知道“DOM”是 Lawnchair 的默认适配器,但我的印象是 DOM 存储是持久的。关于为什么它不适合我的任何想法?我已经在运行 Chrome 的 Win7 机器以及使用 PhoneGap 的 Android 设备上对此进行了测试。同样,它在单个应用程序启动的范围内工作,但存储的对象不会在后续应用程序启动中持续存在。我的代码如下。为了在后续启动时测试 Get,我只是将实例化并保存部分注释掉。

更新:我尝试使用Google Gears sqlite adapter,但在调试时,它挂在我实例化的第一行,并且从未超过该点。这一切看起来很简单,但实际上无法让它发挥作用。什么给了?

new Lawnchair({
adapter: "dom",
name: "ce-app-db"
}, function () {
this.nuke();
});

Lawnchair({ name: 'ce-app-db' }, function () {
    alert('storage open - save');
    this.save({ key: 'insps', value: msg });
});

Lawnchair({ name: 'ce-app-db' }, function () {
    alert('storage open - get');
    this.get('insps', function (obj) {
    if (obj) {
        var index = 0;
        $.each(obj.value, function (i, item) {
            if (item != null) {
                index++;
            }
        });
        alert(index + ' cases found');
    }
    else {
        alert('cases not found');
    }
});
});

【问题讨论】:

  • 您在加载数据库时的设置代码(第 4 行)是this.nuke(),因此每次尝试加载数据库时,都会删除其中的所有条目。

标签: android cordova lawnchair


【解决方案1】:

好的,真的不知道我做错了什么,但是在将我的代码重写为更像this example 之后,我的数据现在在应用程序启动之间保持不变。

【讨论】:

    猜你喜欢
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    相关资源
    最近更新 更多