-
16 Apr 2012 1:49 AM #1
Unanswered: Localstorage
Unanswered: Localstorage
Hi,
I am trying to store the username of my user in a localstorage. Everything works except after setting the variable "username" to the storage and then recalling the page in chrome (F5) the storage is not getting the username, i checked in the debug modus the data is there, but i retrive null from getbyid
thanks in advance...
Code://Create the localstore var localstore = Ext.create('Ext.data.Store', { model: 'app.model.LocalStore' }); localstore.load(); if(localstore.getById('username')!=null){ console.log('Loaded:'+localstore.getById('username').get('email')) } console.log(localstore.add({id: 'username',email: 'mchopra2@gmail.com'})); console.log(localstore.getById('username').get('email')); localstore.sync();
Code:Ext.define('app.model.LocalStore', { extend: 'Ext.data.Model', config: { fields: ['id','email'], proxy: { type: 'localstorage', id : 'localstore' } } });
-
16 Apr 2012 3:19 AM #2
javascript doing asynchronous....
you called load() method. this mean still processing.
If you call event like, then you should use callback...
Code:localstore.load(); <<--
Code:localstore.load(function() { // code here }); <<--
-
16 Apr 2012 4:05 AM #3
Be careful!
Localstorage ist not working on phones:
http://www.sencha.com/forum/showthread.php?194644-Localstorage-not-working-in-native-iOS-or-native-Android-application&highlight=localstorage
-
16 Apr 2012 10:22 AM #4
what can I do instead? I would like to store the username locally so that when the user comes back to application I have a unique identifier and keep him logged on..
-
16 Apr 2012 10:26 AM #5
I tried but still the getById returns null/undefined.
<CODE>
//Create the localstore
var localstore = Ext.create('Ext.data.Store', {
model: 'app.model.LocalStore'
});
localstore.load(function() {
if(localstore.getById('username')!=null){
console.log('Loaded:'+localstore.getById('username').get('email'))
}
});
localstore.setData({id: 'username',email: 'm@gmail.com'});
localstore.getById('username').get('email');
localstore.sync();
</CODE>


Reply With Quote