PDA

View Full Version : How to access to a parameter defined into a parent element



shensi
21 May 2012, 12:59 PM
Hi,
With a piece of code It will be easier to explain...

I have many tabs, in each of them I declared an id dID.


items.push({
inTab: true,
xtype: 'devicelog',
device: device,
dID: dID,
closable: false,
listeners: {
scope: this
}
});


devicelog is my child form panel. I would like to access to this parent variable (dID).

This dID value should be associated to this data parameter as showed below.

{
xtype: 'button',
text : 'On',
//parentContainer:this,
//enableToggle: true,
/*handler: function() {
alert('You clicked the button!')
},*/
listeners: {
click: function() {
// this == the button, as we are in the local scope
//this.setText('On '+this.parentContainer.getId());
Ext.Ajax.request({
method:'PUT',
type:'rest',
url: 'app.php/execs',
params: {
data: Should-be-the-dID-parameter,
action:'on'
},
success: function(response){
var text = response.responseText;
// process server response here
}
});
}
}
},


Do you know which method can I use to get the dID value ?
Thank you for your help and your time !
Shensi

debabrata
21 May 2012, 11:06 PM
First access the devicelog component and then with dot operator access the diD config.

sword-it
21 May 2012, 11:14 PM
Hi shensi,

You just simply find the parent panel which contain dID property like...



var id = childFormPanel.findParentByType('tabpanel').dID;


For more information see http://docs.sencha.com/ext-js/4-0/#!/api/Ext.grid.Panel-method-findParentBy

shensi
22 May 2012, 1:59 PM
Hi sword-it,

I tried what you said, but it still doesn't work :-(

This is my modification and my understanding :


{ xtype: 'fieldset',
//flex: 1,
title: 'Quick test',
defaultType: 'checkbox', // each item will be a checkbox
layout: 'anchor',
items: [
{
xtype: 'button',
text : 'On',
//parentContainer:this,
//enableToggle: true,
handler: function(btn, e) {
//This is an alias of my tabpanel item -> firebug says : btn.findParentByType("deviceinfotab") is undefined
var id = btn.findParentByType('deviceinfotab').dID;
//This is an alias of a deviceinfo tabpanl which contain all tabs -> firebug says : the console says 'undefined' without error
var id = btn.findParentByType('deviceinfo').dID;
console.log(id);
},
listeners: {
click: function() {
// this == the button, as we are in the local scope
//this.setText('On '+this.parentContainer.getId());
Ext.Ajax.request({
method:'PUT',
type:'rest',
url: 'app.php/execs',
params: {
data: this.id,
action:'on'
},
success: function(response){
var text = response.responseText;
// process server response here
}
});
}
}

},


This is the modification of my tab item :


items.push({ inTab: true,
alias: 'widget.deviceinfotab',
xtype: 'deviceaction',
device: device,
dID: dID,
closable: false,
listeners: {
scope: this
}
});

Hope I will find soon...
Cheers

sword-it
24 May 2012, 4:26 AM
Did you try to debug:


var parent = btn.findParentByType('deviceinfotab');


if 'deviceinfotab' is found and it contains dID property then you can get the dID value. That would certainly work.

According to your latest code you can try the following:


var id = btn.findParentByType('deviceaction').dID;

shensi
24 May 2012, 1:09 PM
Nice one boss,

It was exactly this line to write :



var id = btn.findParentByType('deviceaction').dID;

Thank you very much for your help