PDA

View Full Version : How do you reuse the stored data in localstorage?



zuriq
25 Apr 2011, 2:54 PM
Hi,

I am very new to Sencha Touch. I really like the product, but I'm having trouble getting through this problem. Please help. I've been at this for 3 days!!!

I was able to store the data in localstorage to reuse. But I am not able to reuse the data from the store in any other panels (or pages) and parameters in url. I can use the data like app.UserStore.getAt(0).get('id') by calling it in the event handler but not in the url's param or the value I assign.

Is this simply NOT possible to use app.UserStore.getAt(0).get('id') format anywhere else? If so, what are my options to get around this problem?

-- stored data in localstorage after login

Ext.regModel('User', {
fields: ['id', 'email'],

proxy: { type: 'localstorage', id: 'user-localstorage' }
});


app.UserStore = new Ext.data.Store({
model: 'User',
storeId: 'ConfigStore',
autoLoad: true
});

-- source for reusing data in localstorage
Highlighted in blue: I can see the stored data.
Highlighted in red: I get an error due to this code. (the page doesn't display)


initComponent: function(){

var toolbarBase = {
xtype: 'toolbar',
title: 'Group Chat'
};

toolbarBase.items = [{ xtype: 'spacer', flex: 1 }, {
iconCls: 'action',
iconMask: true,
scope: this,
ui: 'plain',
handler: function(){

Ext.Msg.alert('Login Sucess', app.UserStore.getAt(0).get('id'), Ext.emptyFn);
}
}];


this.dockedItems = toolbarBase;

var searchModel = Ext.ModelMgr.getModel("Search");

var search = new searchModel({
query: app.UserStore.getAt(0).get('id')
});

var store = search.tweets();

var tweetList = {
cls: 'timeline',
emptyText : '<p class="no-searches">No Message Found</p>',

disableSelection: true,

store: store,

plugins: [ {
ptype: 'pullrefresh'
}],

itemCls: 'tweet',
itemTpl: new Ext.XTemplate(
'<div class="avatar"<tpl if="profile_image_url"> style="background-image: url({profile_image_url})"</tpl>></div>',
'<div class="x-tweetanchor"></div>',
'<div class="tweet-bubble">',
'<div class="tweet-content">',
'<h2>{from_user}</h2>',
'<p>{text:this.linkify}</p><strong></strong>',
'<span class="posted">{created_at}</span>',
'</div>',
'</div>',
{
linkify: function(value) {
return value.replace(/(http:\/\/[^\s]*)/g, "<a target=\"_blank\" href=\"$1\">$1</a>");
}
}
)
};

this.list = new Ext.List(Ext.apply(tweetList, {
fullscreen: true
}));

this.listpanel = new Ext.Panel({
layout: 'fit',
items: this.list,
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
ui: 'gray',
items: [{
xtype: 'textfield',
placeHolder: 'Share your thoughts with your Peers',
name: 'searchfield'
}]
}]
});

this.items = this.listpanel;
this.list.store.load();

app.views.ChatList.superclass.initComponent.call(this);
}

Tyorke
25 Apr 2011, 3:27 PM
Set data in localstorage:



localStorage.setItem('username', 'jdoe');


Get data in localstorage:


localStorage.getItem('username');

zuriq
25 Apr 2011, 3:52 PM
Thank you for your reply.

I tested your code but that didn't work. Do you any other suggestion...?

Thank you so much for your quick response.

zuriq
25 Apr 2011, 4:04 PM
@Tyorke

Thank you so much! It worked!!!

I was so distraught that I tested it too quickly. It worked!

zuriq
6 May 2011, 5:33 PM
:):( I have one more question...


I can reuse all of the localstorage data for all other panels. But when I clear or restore the localstorage data, it doesn't work in other panels, unless I refresh the whole thing. So the end result is that the result is always one step behind the action.

My question is... How can I reuse the stored data within the same panel so that I don't have to refresh each panel especially within card?:"

Rhoover
8 May 2011, 5:50 AM
:):( I have one more question...


I can reuse all of the localstorage data for all other panels. But when I clear or restore the localstorage data, it doesn't work in other panels, unless I refresh the whole thing. So the end result is that the result is always one step behind the action.

My question is... How can I reuse the stored data within the same panel so that I don't have to refresh each panel especially within card?:"

bump with same question: re-using stored data, say for an edit, requires an f5 refresh.