-
26 Aug 2011 3:07 PM #1
Answered: Using objects extending from the same class in the same page
Answered: Using objects extending from the same class in the same page
Hi all, i defined a class called A in A.js, then i use Ext.create to create 2 objects with different configure parameters in one page, to my surprise, it seems that the last one grabs off that belongs to the first one. for instance, I defined a toolbar with a comobox in class A, then new 2 objects a,b in one page, i will see only b has the combobox, and there are 2. idunno if i use this in a correct way. anyway, i have replace all the id hard coding in the class to avoid repeating id, but it's useless
-
Best Answer Posted by skirtle
It would be much easier to help you if you posted some code demonstrating a minimal test case.
If you are unfamiliar with JavaScript prototypes then I suggest you do some research on them before reading the rest of my post.
I suspect you've put the instances of your toolbar items on the prototype so that they are shared. e.g. If you do something like this it won't work:
It is important to realize that the tbar array is added to the prototype of the class so the same instance of the combobox will be used by all instances of A.Code:Ext.define('A', { tbar: [ new Ext.form.field.ComboBox(...) ] });
If this is your problem then you will either need to create the tbar in initComponent() or specify it using xtypes instead. The xtype approach is neater but not as flexible.
-
29 Aug 2011 3:19 AM #2
It would be much easier to help you if you posted some code demonstrating a minimal test case.
If you are unfamiliar with JavaScript prototypes then I suggest you do some research on them before reading the rest of my post.
I suspect you've put the instances of your toolbar items on the prototype so that they are shared. e.g. If you do something like this it won't work:
It is important to realize that the tbar array is added to the prototype of the class so the same instance of the combobox will be used by all instances of A.Code:Ext.define('A', { tbar: [ new Ext.form.field.ComboBox(...) ] });
If this is your problem then you will either need to create the tbar in initComponent() or specify it using xtypes instead. The xtype approach is neater but not as flexible.
-
2 Sep 2011 4:19 AM #3
Thanks, it's really helpful, so i need to use lazy init as what u mentioned to use a {}with xtype. thank you


Reply With Quote