PDA

View Full Version : Doubt about JsonStore



attu
6 Oct 2010, 2:17 AM
Hello!

I've got a doubt about JsonStore. Is there any way to keep data in the store after load? I need to operate with the store but after load, the information seems to be disappeared :(.

What am i doing wrong? Am i loosing any config. option?

Thanks in advance!

Condor
6 Oct 2010, 2:28 AM
Load is asynchronous! You have to wait for the server to respond before you can access the data.

You can do that by using a load event handler or the load method callback.

attu
6 Oct 2010, 2:34 AM
Uhm... I know that, but i'd like to keep data in the store after load event... I can access to data 1 minute after maybe...

Thanks Condor!

Condor
6 Oct 2010, 2:39 AM
Data in a store doesn't magically disappear. Are you sure you are not clearing the store?

Maybe you should post some code of what you are actually trying to do...

attu
6 Oct 2010, 3:01 AM
Ok :).

This is the situation (a little bit complicated!):

i've got a TabPanel with some items (a ComboBox and TextFields and Store) and an EditorGridPanel with data. Depending on the rows of the EditorGridPanel, the panel's store changes.

When i load the window i load the store. onLoad, i can see items in the store, but afterload, store seems to be empty.

This is the code:


var tabPanelFianzas = Ext.extend(Ext.TabPanel,{
onRender: function() {
tabPanelFianzas.superclass.onRender.apply(this, arguments);
},
height: 140,
activeTab: 0,
radio: null,
frame: true,
border: false,
cargarFianza: function(empresa){
if(obj.getCount() > '0'){
this.setCampos(empresa);
}else{
var fianza = this.store.recordType;
var f = new fianza({
idFianza: null,
empresa: '',
importeFP: null,
fechaSolicitudFP: null,
bancoFP: null,
polizaFP: null
});
this.store.insert(this.store.getCount(), f);
}
},
addCampo: function(campo, valor){
var i=this.store.find('empresa',Ext.getCmp('comboFianzas').getValue());
var record = this.store.getAt(i);
record.set(campo,valor);
},
setCampos: function(empresa){
var i=this.store.find('empresa',empresa);
Ext.getCmp('importeFP').setValue(this.store.getAt(i).data.importeFP);
Ext.getCmp('fechaSolicitudFP').setValue(this.store.getAt(i).data.fechaSolicitudFP);
Ext.getCmp('bancoFP').setValue(this.store.getAt(i).data.bancoFP);
Ext.getCmp('polizaFP').setValue(this.store.getAt(i).data.polizaFP);
Ext.getCmp('fechaFianza').setValue(this.store.getAt(i).data.fechaFianza);
Ext.getCmp('checkFianza').setValue(this.store.getAt(i).data.checkFianza);
},
store: new Ext.data.JsonStore({
url: '../napp/Fianzas/get-fianzas-oferta',
root: 'filas',
autoLoad: true,
totalProperty: 'total',
fields: ['idFianza','empresa','importeFP', 'fechaSolicitudFP',
'bancoFP', 'polizaFP', 'fechaFianza', 'checkFianza'],
listeners: {
load: function(obj){
console.log(obj); // If i do it here, i see data.
if(obj.getCount() > 0){
Ext.getCmp('importeFP').setValue(obj.getAt(0).data.importeFP);
Ext.getCmp('fechaSolicitudFP').setValue(obj.getAt(0).data.fechaSolicitudFP);
Ext.getCmp('bancoFP').setValue(obj.getAt(0).data.bancoFP);
Ext.getCmp('polizaFP').setValue(obj.getAt(0).data.polizaFP);
Ext.getCmp('fechaFianza').setValue(obj.getAt(0).data.fechaFianza);
Ext.getCmp('checkFianza').setValue(obj.getAt(0).data.checkFianza);
}
}
}
}),
initComponent: function () {
Ext.apply(this, {
items:[{
title: 'Sumario Fianzas',
frame: true
},{
title: 'Aņadir Fianza',
frame: true,
layout: 'form',
items:[{
xtype: 'combo',
store: this.store,
id: 'comboFianzas',
displayField: 'empresa',
fieldLabel: 'Empresa',
mode: 'local',
triggerAction: 'all',
anchor: '30%',
listeners:{
select: function(){
this.setCampos(Ext.getCmp('comboFianzas').getValue());
},
scope: this
}
},{
... ITEMS ...
}]
}]
});

tabPanelFianzas.superclass.initComponent.apply(this, arguments);
}
});

Ext.reg('tabPanelFianzas', tabPanelFianzas);
Combo's store is the same than JsonStore of the TabPanel. When i try to get info from the console, store is empty (after load).

Thanks!

Condor
6 Oct 2010, 3:49 AM
What exactly are you entering on the console?

fabio.parra
6 Oct 2010, 3:59 AM
Hey...see this screencast (http://tdg-i.com/392/ext-js-screencast-the-dangers-of-ext-getcmp)about Ext.getCmp

Condor
6 Oct 2010, 4:14 AM
So you are doing something like:

console.log(Ext.getCmp('comboFianzas').store.getCount());

attu
6 Oct 2010, 5:42 AM
Yes, i watched that screencast :). I'm trying to avoid the use of Ext.getCmp. Anyway, that's just a test :).

Yes, i write something like that. But, i'm really sorry because (i don't know why) it works rightnow... Thanks for your help :).