PDA

View Full Version : HELP!!! passing a variable from a function to the main?!?!



grubby69
13 Sep 2011, 1:23 AM
Hi!
I have a big problem that maybe it's a stupid misunderstanding...
I cannot pass a changed value of a variable from the handler to the main!!!
I want to have a List and when I tap on a row(parent) I want to have a second list(child) and then tapping on a row I will have the expanded data.
The problem is that when I tap the first time to build the second list of childs rows ,the Store load itself with the extraparams 'r_idx_p' value to NULL and so the server don't make the right query and the list is NULL.
Infact if I set forcing the r_idx_p to 1 (a correct value of the parent,the query is ok and jsn is ok and the second list is right rendered.
The problemis ONLY pass the r_idx_p value taken byt the event to the store.
But HOW?????

here is the code of the handler:


//gestione del tap
//setto sublist slide
tapSubListHandler = function(list, index, item, e) {

//assegno valori dei campi record
rec = Ext.getCmp('listId').getStore().getAt(index);
r_idx_p = parseInt(rec.get('IDX_PADRE'));//eseguo il parseInt per trasformare l'oggetto in numero intero


Ext.getCmp('sublistId').getStore().load();
mainPanel.setActiveItem(mySlideSubList, {type: 'slide'});
//mainPanel.setActiveItem(mySlideSubList, {type: 'slide'});
//mySlideSubList.doLayout();


};

and here is the code of the store:


//inizializzo variabili
r_idx_p = 'null';
r_idx_f = 'null';
r_data = 'null';
r_tinfo = 'null';
r_vuser = 'null';
r_vimg = 'null';



substore = new Ext.data.Store({
storeId: 'mysubStoreId',
model : 'List',
proxy: {
type: 'ajax',
url : 'app/lettura_sub_db_json_old.php',
extraParams: {datap: r_idx_p},
reader: {
type: 'json',
root: 'list'
}
},
autoLoad: false

});

grubby69
13 Sep 2011, 3:25 AM
Please could someone close this?

I have rsolved this problem configuring the proxy for the store NOT in the creation of the store but in the function adding the proxy by the setProxy method.

here is the code:


//gestione del tap
//setto sublist slide
tapSubListHandler = function(list, index, item, e) {

//assegno valori dei campi record
rec = Ext.getCmp('listId').getStore().getAt(index);
r_idx_p = parseInt(rec.get('IDX_PADRE'));//eseguo il parseInt per trasformare l'oggetto in numero intero

//alert(r_idx_p);

Ext.getCmp('sublistId').getStore().setProxy({
type: 'ajax',
url : 'app/lettura_sub_db_json_old.php',
extraParams: {datap: r_idx_p},
reader: {
type: 'json',
root: 'list'
}
});

Ext.getCmp('sublistId').getStore().load();
mainPanel.setActiveItem(mySlideSubList, {type: 'slide'});
//mainPanel.setActiveItem(mySlideSubList, {type: 'slide'});
//mySlideSubList.doLayout();


};




So I think that the problem was due to the asyncrosnuos call of the ajax and the assinging value to the variable that should be passed via extraparams.
Doing it inside the function all is ok!
B)

Great!