如何在Sencha Touch / PhoneGap中存储本地数据
How to store local data in Sencha Touch / PhoneGap?
我设置了一个SenchaTouch/PhoneGap应用程序,从外部XML提要提取信息。我的问题是,这显然只能在在线时工作。
如何将来自外部提要的信息存储在本地存储中以供离线使用?
下面是应用数据store代码:
App.eventstore = new Ext.data.Store({
model: 'Event',
sorters: 'title',
autoLoad: true,
getGroupString : function(record) {
return record.get('title')[0];
},
proxy: {
type: 'ajax',
url: 'http://the-url-to-the-file.xml',
reader: {
idProperty: 'id',
type: 'xml',
root: 'events',
record: 'event'
}
}
});
App.eventstore.read();
在Ilya139的回答后更新:
我已经实现了代码,但现在我的列表是空的…(
App.eventstore = new Ext.data.Store({
model: 'Event',
sorters: 'title',
autoLoad: true,
getGroupString : function(record) {
return record.get('title')[0];
},
proxy: {
type: 'ajax',
url: 'http://the-url-to-the-file.xml',
reader: {
idProperty: 'id',
type: 'xml',
root: 'events',
record: 'event'
}
}
});
App.eventstore.read();
App.eventstore.each(function(record){record.save();});
App.offlineeventstore = new Ext.data.Store({
model: 'Event',
sorters: 'title',
autoLoad: true,
getGroupString : function(record) {
return record.get('title')[0];
},
proxy: {
type: 'localstorage',
id:'events'
}
});
App.offlineeventstore.read();
Ext.regModel('Event', {
fields: [
{name: 'id', mapping: '@id', type: 'integer'},
{name: 'title', type: 'string'},
etc etc...
],
proxy: {
type: 'localstorage',
id:'events'
}
});
列表设置为使用离线商店:
items: [{
xtype: 'list',
store: App.offlineeventstore,
itemTpl: '{title}',
grouped: true,
indexBar: true,
将此添加到Event
模型:
proxy: {
type: 'localstorage',
id:'events'
}
然后对于你下载的每个事件,像这样调用save()
:
App.eventstore.each(function(record){record.save();});
然后加载:
App.offlinestore = new Ext.data.Store({
model: 'Event',
sorters: 'title',
autoLoad: true,
getGroupString : function(record) {
return record.get('title')[0];
},
proxy: {
type: 'localstorage',
id:'events'
}});
App.eventstore.load(function(){
App.eventstore.each(function(record){record.save();});
offlineeventstore.load();
});
相关文章:
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 如何以特定格式存储数据?在WYSWYG中
- web浏览器中的离线应用程序存储数据并在之后上传
- 在firebase(web)上存储数据时出现问题
- 使用会话Javascript存储数据
- 通过CK编辑器获取值和存储数据
- 存储数据的最佳方式是什么,以便与jquery一起使用
- 如何在网页之间存储数据
- jQuery 设置和获取下拉列表和输入的本地存储数据
- 如何通过HTML 5 javascript在本地ipad / iPhone上存储数据,并在设备上线时提交
- 使用 Cookie 存储数据
- 如何将本地存储数据提交到 Django
- 如何在循环jQuery中的数组中存储数据
- 正在从表行中删除本地存储数据
- 在web应用程序中存储数据
- 自动将jqgrid滚动到具有存储数据的单元格的当前日期列和闪烁效果
- 如何将复选框呈现为从本地存储数据中选中的复选框
- 如何使用Ajax检索和存储数据
- 方法存储数据,直到浏览器关闭
- 如何在redux sagas完成之前通过meta标签加载初始存储数据