Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sencha touch 不在sencha中的localstorage上存储值_Sencha Touch_Local Storage_Sencha Touch 2.1 - Fatal编程技术网

Sencha touch 不在sencha中的localstorage上存储值

Sencha touch 不在sencha中的localstorage上存储值,sencha-touch,local-storage,sencha-touch-2.1,Sencha Touch,Local Storage,Sencha Touch 2.1,我试图离线存储数据,但这里我想在localstorage上存储数据,无法存储,所有值在localstorage中变为null 这是基于, 型号: *Online.js* Offline.js Ext.define('default.model.Offline', { extend: 'Ext.data.Model', config: { fields: [ 'cat_id', 'category_na

我试图离线存储数据,但这里我想在localstorage上存储数据,无法存储,所有值在localstorage中变为null

这是基于,

型号: *Online.js*

Offline.js

Ext.define('default.model.Offline', {
  extend: 'Ext.data.Model',
  config: {
    fields: [
                    'cat_id',
                    'category_name'
                ],
    identifier:'uuid', // IMPORTANT, needed to avoid console warnings!
    proxy: {
      type: 'localstorage',
      id  : 'category'
    }
  }
});
Ext.define('SF.model.Online', {
    extend : 'Ext.data.Model',    
    config: {
        fields: ['cat_id','category_name'],
   }
});

Ext.define('SF.model.Offline', {
    extend : 'Ext.data.Model',
    config: {
        fields: ['cat_id','category_name'],
        identifier:'uuid', 
        proxy: {
          type: 'localstorage',
          id  : 'category'
        }
    }
});
商店:

Ext.define('default.store.News', {
  extend:'Ext.data.Store',


  config:{
    model:'default.model.Online',
    proxy: {
      timeout: 3000, // How long to wait before going into "Offline" mode, in milliseconds.
      type: 'ajax',
      url: 'http://alucio.com.np/trunk/dev/sillydic/admin/api/word/categories/SDSILLYTOKEN/650773253e7f157a93c53d47a866204dedc7c363?_dc=1376475408437&page=1&start=0&limit=25' , // Sample URL that simulates offline mode. Example.org does not allow cross-domain requests so this will always fail
      reader: {
                type: "json",
                rootProperty: "data"
            }
      },
    autoLoad: true
  }
});
Ext.define('default.controller.Core', {
  extend : 'Ext.app.Controller',

  config : {
    refs    : {
      newsList   : '#newsList'
    }
  },
  init : function () {
    var onlineStore = Ext.getStore('News'),
      localStore = Ext.create('Ext.data.Store', {
        model: "default.model.Offline"
      }),
      me = this;

    localStore.load();

    onlineStore.on('refresh', function (store,record) {
     Ext.Msg.alert('Notice', 'You are in online mode', Ext.emptyFn);
      //  console.dir(record.data.name);
        console.dir(record.get('category_name'));
        console.log(record.items[0].raw.category_name);
        console.log(record.get('category_name'));
      // Get rid of old records, so store can be repopulated with latest details
      localStore.getProxy().clear();

      store.each(function(record) {

        var rec = {
          name : record.data.category_name+ ' (from localStorage)' // in a real app you would not update a real field like this!
        };

        localStore.add(rec);
        localStore.sync();
      });

    });
      onlineStore.getProxy().on('exception', function () {
      me.getNewsList().setStore(localStore); //rebind the view to the local store
      localStore.load(); // This causes the "loading" mask to disappear
      Ext.Msg.alert('Notice', 'You are in offline mode', Ext.emptyFn); //alert the user that they are in offline mode
    });

  }
});
控制器:

Ext.define('default.store.News', {
  extend:'Ext.data.Store',


  config:{
    model:'default.model.Online',
    proxy: {
      timeout: 3000, // How long to wait before going into "Offline" mode, in milliseconds.
      type: 'ajax',
      url: 'http://alucio.com.np/trunk/dev/sillydic/admin/api/word/categories/SDSILLYTOKEN/650773253e7f157a93c53d47a866204dedc7c363?_dc=1376475408437&page=1&start=0&limit=25' , // Sample URL that simulates offline mode. Example.org does not allow cross-domain requests so this will always fail
      reader: {
                type: "json",
                rootProperty: "data"
            }
      },
    autoLoad: true
  }
});
Ext.define('default.controller.Core', {
  extend : 'Ext.app.Controller',

  config : {
    refs    : {
      newsList   : '#newsList'
    }
  },
  init : function () {
    var onlineStore = Ext.getStore('News'),
      localStore = Ext.create('Ext.data.Store', {
        model: "default.model.Offline"
      }),
      me = this;

    localStore.load();

    onlineStore.on('refresh', function (store,record) {
     Ext.Msg.alert('Notice', 'You are in online mode', Ext.emptyFn);
      //  console.dir(record.data.name);
        console.dir(record.get('category_name'));
        console.log(record.items[0].raw.category_name);
        console.log(record.get('category_name'));
      // Get rid of old records, so store can be repopulated with latest details
      localStore.getProxy().clear();

      store.each(function(record) {

        var rec = {
          name : record.data.category_name+ ' (from localStorage)' // in a real app you would not update a real field like this!
        };

        localStore.add(rec);
        localStore.sync();
      });

    });
      onlineStore.getProxy().on('exception', function () {
      me.getNewsList().setStore(localStore); //rebind the view to the local store
      localStore.load(); // This causes the "loading" mask to disappear
      Ext.Msg.alert('Notice', 'You are in offline mode', Ext.emptyFn); //alert the user that they are in offline mode
    });

  }
});
我想,我没有从这个记录.data.category\u nam中获得价值。这里我从中获得第一个值:记录.items[0].raw.category\u name。那么如何在本地存储中存储。 和查看文件:

Ext.define('default.view.Main', {
  extend : 'Ext.List',

  config : {
    id               : 'newsList',
    store            : 'News',
    disableSelection : false,
    itemTpl          : Ext.create('Ext.XTemplate',
      '{category_name}'
    ),
    items            : {
      docked : 'top',
      xtype  : 'titlebar',
      title  : 'News List'
    }
  }
});
在localstorage中,以下输出:

category-5ea01a8d-ef1e-469e-8ec4-790ec7306aaf
{"cat_id":null,"category_name":null,"id":"5ea01a8d-ef1e-469e-8ec4-790ec7306aaf"}
category-f3e090dd-8f25-4b20-bb6e-b1a030e07900
{"cat_id":null,"category_name":null,"id":"f3e090dd-8f25-4b20-bb6e-b1a030e07900"}
category-5148e6eb-85ae-4acd-9dcd-517552cf5d97
{"cat_id":null,"category_name":null,"id":"5148e6eb-85ae-4acd-9dcd-517552cf5d97"}
category-ec23ff8b-1faa-4f62-9284-d1281707a9bc
{"cat_id":null,"category_name":null,"id":"ec23ff8b-1faa-4f62-9284-d1281707a9bc"}
category-6c1d

我已在视图中显示,但无法将其存储在本地存储中以供脱机提议。如果我出错,则无法获取它。

您创建的记录应与
SF.model.offline
模型匹配

在下面的代码中

 var rec = {
  // name is the field name of the `SF.model.Offline` model.
  name : record.data.category_name+ ' (from localStorage)' 
 };

 localStore.add(rec);
 localStore.sync();
但是您可以看到,在
SF.model.Offline
model中没有名为name的字段

这是你应该做的

型号

Ext.define('default.model.Offline', {
  extend: 'Ext.data.Model',
  config: {
    fields: [
                    'cat_id',
                    'category_name'
                ],
    identifier:'uuid', // IMPORTANT, needed to avoid console warnings!
    proxy: {
      type: 'localstorage',
      id  : 'category'
    }
  }
});
Ext.define('SF.model.Online', {
    extend : 'Ext.data.Model',    
    config: {
        fields: ['cat_id','category_name'],
   }
});

Ext.define('SF.model.Offline', {
    extend : 'Ext.data.Model',
    config: {
        fields: ['cat_id','category_name'],
        identifier:'uuid', 
        proxy: {
          type: 'localstorage',
          id  : 'category'
        }
    }
});
商店

Ext.define('SF.store.Category', {
    extend : 'Ext.data.Store',   
    config : {
        model : 'SF.model.Online',
        storeId : 'category',
        proxy: {
            timeout: 3000, 
            type: 'ajax',
            url: 'same url' , 
        reader: {
                type: "json",
                rootProperty: "data"
            }
      },
        autoLoad : true
    }
});
在控制器中

 var onlineStore = Ext.getStore('category'),
 localStore = Ext.create('Ext.data.Store', { 
        model: "SF.model.Offline"
    }),
    me = this;

  localStore.load();  

  onlineStore.on('refresh', function (store, records) {  
    localStore.getProxy().clear();
    onlineStore.each(function(record) {

     //You creating record here, The record fields should match SF.model.Offline model fields
      var rec = {
        cat_id : record.data.cat_id + ' (from localStorage)',
        category_name : record.data.category_name + ' (from localStorage)'
      };

      localStore.add(rec);
      localStore.sync(); 
    });
  });  

  onlineStore.getProxy().on('exception', function () {
    me.getNewsList().setStore(localStore); 
    localStore.load(); 
    Ext.Msg.alert('Notice', 'You are in offline mode', Ext.emptyFn);
 });

非常感谢。非常感谢。如果我有word的定义,如何在localstorage中存储并显示在Ext.XTemplate上。你有什么想法吗。我的JSON看起来像这个有定义的词。@Google\u Android\u爱好者。。这就是你在onlineStore.getProxy()中所做的。在('exception',function(){..})上,如果你的应用程序不在线,你可以在新闻列表中设置localStore。我尝试了以下操作:message:record.data.message,definition:record.data.definitions.definition,ratings:“红色”。这里的消息工作正常,在statis中的评级也正常,但如果有定义,它不起作用,请帮助我。@Google\u Android\u爱好者问一个新问题,并给出明确解释或更新此问题