1. #1
    Touch Premium Member liuxing_sc's Avatar
    Join Date
    Aug 2011
    Location
    China
    Posts
    38
    Vote Rating
    0
    liuxing_sc is on a distinguished road

      0  

    Default 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

  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:

    Code:
    Ext.define('A', {
        tbar: [
            new Ext.form.field.ComboBox(...)
        ]
    });
    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.

    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.

  3. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,624
    Vote Rating
    331
    Answers
    550
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    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:

    Code:
    Ext.define('A', {
        tbar: [
            new Ext.form.field.ComboBox(...)
        ]
    });
    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.

    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.

  4. #3
    Touch Premium Member liuxing_sc's Avatar
    Join Date
    Aug 2011
    Location
    China
    Posts
    38
    Vote Rating
    0
    liuxing_sc is on a distinguished road

      0  

    Default


    Thanks, it's really helpful, so i need to use lazy init as what u mentioned to use a {}with xtype. thank you

Thread Participants: 1