【问题标题】:Sencha Touch 2.0.1.1 Local Store not saving valuesSencha Touch 2.0.1.1 本地存储不保存值
【发布时间】:2013-05-13 15:46:55
【问题描述】:

我正在尝试存储在本地存储中,但它没有被存储。 我需要将两个值作为状态 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");
}

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

感谢您的帮助。 约瑟夫

【问题讨论】:

    标签: extjs touch local-storage local


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-10
      相关资源
      最近更新 更多