大家!我需要读取和写入历史数据数组。我的数据在页面刷新时会丢失数据。谢谢!
问问题
34 次
1 回答
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();
希望我的分享能帮助你遇到同样的问题!
于 2013-07-05T03:08:30.627 回答