【问题标题】:Save and Load Data Model in Sench Touch 2.1在 Sench Touch 2.1 中保存和加载数据模型
【发布时间】:2013-07-03 03:31:02
【问题描述】:

大家! 我需要读取和写入历史数据数组。我的数据在页面刷新时会丢失数据。谢谢!

【问题讨论】:

  • 我尝试在 Sencha Touch 中使用 localstore,但它并没有解决我的问题。我的代码是这样的:console.log("====Check History===="); var history = Ext.getStore("HistoryTracking"); // console.log(formValue.fieldTrackingID); history.add(formValue.fieldTrackingID); history.sync();
  • 我想要饼干之类的东西。

标签: sencha-touch-2


【解决方案1】:

我使用 LocalStore HTML 5 解决了这个问题。 使用一些简单的数据,您可以使用:

var data = {};// data is a object just include text and value.
data = {"key1": value1, "key2": value2};// Example, i have a this object. 
//===> We save a object "history" by a string of "data" var. 
localStorage.setItem('history', JSON.stringify(data)); 
// ===> And get it: 
var retrievedHistory = localStorage.getItem('history'); 
// In Sencha Touch, you can parse this oject to your model. and Syns it.

var history = Ext.getStore("HistoryTracking");
history.removeAll();
var num = Object.keys(data).length;
for (i = 0; i < num; i++) 
{
     var string = '' + data["trackID" + i];
            history.add(string);

}
history.sync();

希望我的分享能帮助你遇到同样的问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-23
    • 2016-05-29
    • 1970-01-01
    • 2021-12-15
    • 2019-09-26
    • 1970-01-01
    相关资源
    最近更新 更多