在Sencha Touch 2.1中保存并加载数据模型

时间:2013-07-03 03:31:03

标签: sencha-touch-2

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

1 个答案:

答案 0 :(得分:0)

我使用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();

希望我的分享帮助你解决同样的问题!