PDA

View Full Version : Possible scope problem? Help me understand this... [SOLVED]



madirishman
22 Dec 2010, 7:00 AM
Hi all, below is some code that extends a simple grid. I'm dynamically setting the store url. The problem is that the store loads correctly *the first time*, but as soon as you try to load it again, the dynamic url assignment is lost. I would think that since I set it in the init using "this." I would be able to use it in a subfuction with no problem, but I guess I'm wrong::





logGrid = Ext.extend(logGridUi, {


initComponent: function() {



logGrid.superclass.initComponent.call(this);


var vBtnShowChild = this.btnShowChild;


//dynamically set store urls to use current site root


var vSiteRoot = getURLSiteRoot();


this.store.proxy.setUrl(vSiteRoot+'/cfc/MachineMain_ext.cfc?method=getLogs!');


//listen for show child button click


vBtnShowChild.on({scope:this, 'toggle': this.handleBtnShowChild});
},


//handle child button click

handleBtnShowChild:

function(btn, pressed){

var vLogStore = this.store;



switch(pressed){



casetrue:



vLogStore.setBaseParam('vShowChild', 1);


break;

casefalse:

vLogStore.setBaseParam('vShowChild', 0);
break;
}












vLogStore.load()


}
});
Ext.reg('logGrid', logGrid);



thanks!

danguba
22 Dec 2010, 7:09 AM
Try this:


vBtnShowChild.on('toggle', this.handleBtnShowChild, this);

does it make any difference?

madirishman
22 Dec 2010, 7:17 AM
I get the same result. If I want it to work, I need to add the setUrl() method into the subfunction also, which doesn't seem to make sense.

danguba
22 Dec 2010, 7:37 AM
Aha I think I found it. Try:

this.store.proxy.setUrl(vSiteRoot+'/cfc/MachineMain_ext.cfc?method=getLogs!', true);

madirishman
22 Dec 2010, 7:44 AM
YOU ROCK!!! THANKS!!

Where did you find the second parameter for setURL? I couldn't find it in the API Docs...

danguba
22 Dec 2010, 7:56 AM
You're welcome. Glad I was able to help.
I found second parameter in source code but it is documented in api.
Look here: http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.HttpProxy&member=setUrl

steffenk
22 Dec 2010, 7:57 AM
.

madirishman
22 Dec 2010, 8:26 AM
Ahhh, I was looking at DataProxy and not HttpProxy. Thanks again!

danguba
22 Dec 2010, 8:48 AM
Happy coding ;)