PDA

View Full Version : [SOLVED]Multiple instance and Id



wysman
8 Jun 2010, 6:18 AM
Hi,

I have design a window with Ext designer, It's work fine ! I have set Id for all interesting component.
So the window.ui.js file is Ok, and in window.js i can find easily my component with a findById on this.

Now, i have an other window to design; but this window should be open multiple time, so i can't use Id. I try bad idea !
So i use itemId instead of Id, and i can allocate 2 windows in the same time !
But to access to my component in the window2.js (not .ui.js), i use 'getComponent' and i not easy because i need to explore layout before, and i have js line like that :



var formHandle = this.getComponent(1).getComponent(0).getComponent(0).getComponent(0);
formHandle.getComponent('cb-shift').setValue("Foo");


The first line is horrible, and if i adjust layout of my window, i may broke this code. getComponent is not recursive ...

How to do that, more proper ?

Regards

ldonofrio
8 Jun 2010, 8:43 AM
I think you have to use "refs", see property in designer.

wysman
8 Jun 2010, 12:28 PM
I think you have to use "refs", see property in designer.

Do you mean 'autoRef' ?
Have you a small exemple ?

Thanks

ldonofrio
8 Jun 2010, 12:55 PM
Yes, set autoRef in "cb-shift" component in Designer to for ex. "CbShift" ,and then code "this.CbShift.setValue('foo')" in initComponent method of your root designer component.

wysman
9 Jun 2010, 12:51 AM
Yes, set autoRef in "cb-shift" component in Designer to for ex. "CbShift" ,and then code "this.CbShift.setValue('foo')" in initComponent method of your root designer component.

Not working, on my project.
Does somethings to turn 'on' before, configuration option of EXTJS ?

Thx

jarrednicholls
9 Jun 2010, 4:07 AM
wysman, ldonofrio is correct. When you set the "autoRef" property in the Designer, a "ref" configuration is automatically generated for the component that will place its reference at the top-level (root) parent component. If you try his suggestion again, just make sure you are referencing "this.CbShift" AFTER the call to the superclass' initComponent method:



MyWindow = Ext.extend(MyWindowUi, {
initComponent: function(){
MyWindow.superclass.initComponent.call(this);

this.CbShift.setValue("foo");
}
});


Now I don't know what type of component "CbShift" is, but setValue might not have an effect in the initComponent stage...you may need to attach to CbShift's "render" event and after it is rendered, then set its value.

Hope that helps!

wysman
9 Jun 2010, 4:19 AM
Thanks ldonofrio & jarrednicholls

I just fix the problem.
Instead of export xds project, i have just edit the .ui.js to test, and i forgot to set some '../../../../' before my ref name.
Ref are relative path !

I work fine now !

jarrednicholls
9 Jun 2010, 5:56 AM
The autoRef automatically generates the relative path needed to place the reference at the top-most parent/root component. So when you supply an autoRef of "CbShift", a ref is created that will look like "../../../../CbShift". I'm glad you got it working, but keep in mind that the .ui.js file is overwritten on each project export (the .js file is not).