Javascript 如何在Sencha Touch/PhoneGap中存储本地数据?

Javascript 如何在Sencha Touch/PhoneGap中存储本地数据?,javascript,mobile,extjs,cordova,sencha-touch,Javascript,Mobile,Extjs,Cordova,Sencha Touch,我已经安装了一个SenchaTouch/PhoneGap应用程序,可以从外部XML提要提取信息。我的问题是,这显然只在在线时起作用 如何将外部提要中的信息存储在本地存储器中,以便脱机使用 以下是应用程序数据存储代码: App.eventstore = new Ext.data.Store({ model: 'Event', sorters: 'title', autoLoad: true, getGroupString : function(record) {

我已经安装了一个SenchaTouch/PhoneGap应用程序,可以从外部XML提要提取信息。我的问题是,这显然只在在线时起作用

如何将外部提要中的信息存储在本地存储器中,以便脱机使用

以下是应用程序数据存储代码:

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,

将此添加到
事件
模型:

 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();
});

感谢您的回复,我已经相应地更新了我的问题。您应该在
eventstore
上调用
load()
(它没有
read()
方法)还有一个函数,加载完成后将被调用,并在该函数中保存。检查我更新的答案。非常感谢!现在,在weinre,我看到localstore中的数据,但列表仍然为空……有什么想法吗?我添加了
offlineeventstore.read()
到该函数结束时,它成功了!我以前必须这样做…奇怪。谢谢你的帮助!:)