PDA

View Full Version : how to get treepanel reference



tianhao
25 Jul 2012, 8:57 PM
I have a treepanel in an ext.form.panel using "xtype:'treepanel'" and "id:'theTree'" within items of the ext.form.panel. The question is how I can get the tree reference, or how I can run this js "theTree.expandAll();". Here is the code:
var mainPanel = Ext.create('Ext.form.Panel', {
......
items: [{
xtype: 'treepanel',
id: 'theTree',
title: 'theTree',
bodyPadding: 5,
store: <?php echo $tree_store; ?>
}]
});
theTree.expandAll();//Question here!
Thanks for any advice.

sword-it
25 Jul 2012, 9:48 PM
HI!

you may use .child of your form which requires a selector as a parameter.it basically retrieves the first direct child of this container which matches the passed selector.

eg:-
yourForm.child([ string selector])

check this:-http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.Panel-method-child

tianhao
25 Jul 2012, 10:18 PM
Can you give the explicit sample code for me please. Thank you for your earliest reply.

sword-it
25 Jul 2012, 10:30 PM
Hi!

sample:-

i have a form and i am finding my textfield whose id is 'firstname'.




Ext.create('Ext.form.Panel', {
title: 'Simple Form',
width: 350,
layout: 'anchor',
defaults: {
anchor: '100%'
},
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
id: 'firstname'


}, {
fieldLabel: 'Last Name',
name: 'last',
}],
buttons: [
{
text: 'findFirstNameField',
handler: function (btn) {
var myForm=this.up('form');
,firstNameField = myForm.child('[id=firstname]');
}
}
],
renderTo: Ext.getBody()
});

tianhao
25 Jul 2012, 11:03 PM
Thank you very much!
I have changed code like this:
this.up('form').child('[id=theTree]').expandAll();
It works!