local storage - Using localStorage in store in Sencha Touch -


i'm trying build store elements localstorage in sencha touch application.

the localstorage want data localstorage["feeds"] , looks this:

"[{"title":"title 1","url":"http://stackoverflow.com"},   {"title":"title2","url":"http://google.com"}]" 

i'm trying store following:

var feedspanel; var store; ext.setup({ icon: 'icon.png', glossonicon: false, onready: function(){     ext.regmodel("feedmodel", {         fields: [             { name: "title", type: "string" },             {name: "url", type:"string"}         ]     });     store = new ext.data.store({             proxy: new ext.data.localstorageproxy({                 id: 'feeds'             }),             model:"feedmodel"     }); 

when in chrome try store.load(), fails because of typeerror: cannot read property 'title' of null.

how supposed access every title , every url localstorage?

looking @ example of solitaire game makes me dizzy.

the rest of sencha application not rely on store of now, , loads perfectly. check if there items in store console in chrome.

such localstorage format not specific sencha's stores. if realy need read localstorage formatted in way, may try following. possible :-)

// first prefill localstorage var feeds = [], j = 0; while (j < 25) {     feeds.push({'title': 'title ' + ++j, url: 'http://link' + j + '.com'}); } localstorage.setitem('feeds', ext.encode(feeds));  // sencha touch v1 application new ext.application({     name: 'app',      launch: function() {         var store = new ext.data.jsonstore({             id: 'feedstore',             fields: ['title', 'url'],             autoload: true,             proxy: {                 id: 'feedproxy',                 type: 'memory',                 url: 'feeds',                 create: function () {                     console.log('feed: create');                 },                 read: function (operation, callback, scope) {                     console.log('feed: read');                      var data = localstorage.getitem(this.url),                         i, len, records = [];                      console.log('data: ' + data);                     data = ext.decode(data);                      if (ext.isarray(data)) {                         len = data.length;                         (i = 0; < len; ++i) {                             records.push(new this.model(data[i]));                         };                          // return model instances in result set                         operation.resultset = new ext.data.resultset({                             records: records,                             total  : len,                             loaded : true                         });                          // announce success                         operation.setsuccessful();                         operation.setcompleted();                          // finish callback                         if (typeof callback == "function") {                             callback.call(scope || this, operation);                         }                         ext.getbody().unmask();                     }                 },                 update: function () {                     console.log('feed: update');                 },                 destroy: function () {                     console.log('feed: destroy');                 },                 reader: {                     type: 'json'                 }             }         }).load();          this.viewport = new ext.panel({             fullscreen: true,             layout: 'card',             items: [{                 xtype: 'list',                 itemtpl : '{title}<br />{url}',                 store: store             }]         });     } }); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -