1

我正在尝试存储在本地存储中并且它没有被存储。我需要将两个值作为状态 ID 和许可证类型存储为 1 条记录,下次我将更新它。因此,商店将始终有 1 条记录,如下所示。

{
 'stateId': 'NJ',
 'licenseType': 'BDL'
}

我在过去 2 天尝试了不同的选项,但没有存储。有人可以告诉我我的代码中可能存在什么问题。

注意:我正在尝试测试使用的是 Chrome 浏览器。

商店代码

Ext.define("Sencha.store.TestParams", {    extend: "Ext.data.Store",
    requires: 
    [
        "Ext.data.proxy.LocalStorage"
    ],
    config: {
        model: "Sencha.model.TestParam",
        autoSync: true,
        proxy: {
            type: 'localstorage',
            id: 'ezdt-test-params'
        }
    }
});

型号代码:

Ext.define("Sencha.model.TestParam",
{
    extend: "Ext.data.Model",
    config:
    {
        idProperty: 'id',
        fields:
        [
            { name: 'id', type: 'int' },
            { name: 'stateId', type: 'string' },
            { name: 'licenseType', type: 'string' }
        ]
    }
});

保存代码的实际代码:

var modTestParamInitialValues = Ext.create("Sencha.model.TestParam", {
    id: 'ezdt', //Always Same as there will be only one record.
    stateId: strSelectedState,
    licenseType: strSelectedLicenseType
});
storTestParams.add(modTestParamInitialValues);
storTestParams.sync();

我用来检索存储值的代码。始终将其打印为未设置

var storTestParams = Ext.getStore("TestParams");
console.log("storTestParams#####-->" + storTestParams);
//storTestParams.load();
if(null != storTestParams)
{
    var intTestParamCount = storTestParams.getCount();
    if(intTestParamCount == 0)
    { 
        console.log("Not Set");
    }
    else
    { 
        console.log("Set Correctly");
    }
}
else
{ 
    console.log("Set Correctly");
}

我希望我能提供所有细节。如果您需要更多详细信息,请告诉我。

谢谢你的帮助。约瑟夫

4

1 回答 1

3

不知道你是否明白这一点,因为这个问题很老了。自从我第一次开始使用 Sencha Touch 2 进行开发以来,我在与 localstorage 同步时遇到了不同的麻烦。在同步时帮助我将记录放入 localstorage 的一件事是确保dirty模型实例的属性设置为 true。您可能想尝试一下。请参阅:http ://docs.sencha.com/touch/2-1/#!/api/Ext.data.Model-method-setDirty

于 2013-01-04T21:02:29.823 回答