PDA

View Full Version : Loading JSON-data



Voles
25 Mar 2011, 12:05 AM
Hello everyone,

I'm making an application where a user has to log in. After that I want to show some data from te user.

In the LoginPanel, I'm making a AJAX-request, to check if the username and password are correct. After that, I'm fetching the user-id.

That part is working, next I'm fetching some oter data from the user, to display in an other panel. This is also working, but in my UserPanel, it seems like it doesn't know about the loaded user-data.

Is there a way to tell a panel to wait when some data is fetched from a store? Or to reload the view when a store is updated?

With this code I'm loading the 'sights' of an user. When it's loaded, I show the MainPanel.


Ext.Ajax.request({
url: Stick.configs.userTravelSights + user.id,
timeout: 12000,
method: 'GET',
disableCaching: false,
success: function(xhr) {
sights = xhr.responseText;

// sight store
Stick.stores.sightstore = new Ext.data.JsonStore({
model : 'Sight',
sorters: 'id',
data: Ext.util.JSON.decode(sights)
});

Stick.storesLoaded = true;

Stick.stores.sightstore.load();
Stick.stores.spotstore.load();

Ext.dispatch({
controller: 'MainController',
action: 'map',
displayObject: new Stick.views.MainPanel,
animation: {
type: 'slide',
direction: 'up',
duration: 100
}
});
}
});


In the MainPanel, I'm loading other pages.


Stick.views.MainPanel = Ext.extend(Ext.TabPanel, {
ui: 'toolbar',
tabBar: new Ext.TabBar({
dock: 'bottom',
height: 93
}),
items:
[
{
title: 'Kaart',
items: [
new Stick.views.Map()
]
},
{
title: 'Route',
items: [
new Stick.views.RoutePanel()
]
}
]
});


In the RoutePanel, I want to show the 'sights' from the user, that is stored inside the SightStore. But this doesn't seem to work (it doesn't find any data in the SightsStore).


Stick.views.RoutePanel = Ext.extend(Ext.Panel, {
initComponent: function ()
{
if (Stick.storesLoaded)
{
var arrItems = [];

// loop trough sights
Stick.stores.sightstore.each(function (e){
var panel = new Ext.Panel({
tpl: '{id}'
});

panel.update(e.data);

arrItems.push(panel);
});

this.items = arrItems;
Stick.views.RoutePanel.superclass.initComponent.apply(this, arguments);
}
}
});

Ext.reg('stick-routepanel', Stick.views.RoutePanel);


I really hope someone can help me! Thanks in advance!