Results 1 to 5 of 5

Thread: Component Query - Too many instances?????

  1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Hillsborough, NC
    Posts
    429
    Answers
    3

    Default Component Query - Too many instances?????

    I have defined a top level class:
    Code:
    Ext.define('MyApp.view.MyClass', {
        extend: 'Ext.tree.panel',
        alias: 'widget.mytreepanel'
        ...
    });
    I then use this view as such:
    Code:
    Ext.define('MyApp.view.MyView', {
        extend: 'Ext.tab.panel',
        ...
       items: [
            {
                xtype: 'panel',
                title: 'Tree1',
                items: [
                    {
                        xtype: 'mytreepanel',
                        newAttr: 'treepanel'
                    }
                ]
            },{
                xtype: 'panel',
                title: 'Tree2',
                items: [
                    {
                        xtype: 'mytreepanel',
                        newAttr: 'treepanel'
                    }
                ]
            }
         ],
        ...
    });
    Now when I try to gather all of the tree panels with
    Code:
    var trees = Ext.ComponentQuery.query('mytreepanel');
    
    console.log('number of trees = ' + trees.length);
    I get 3 trees. I only expected the 2 that were in my tab panel. Is this the expected result?

    If I give an additional attribute ('newAttr' above) to the two which are used in the tab panel when they are instantiated, I can query with that attribute and get only those two.
    Code:
    var trees = Ext.ComponentQuery.query('mytreepanel [newAttr="treepanel"]');
    
    console.log('number of trees = ' + trees.length);
    An explanation of what I'm seeing by someone who understands better that I would be appreciated.

    Thanks,
    Worth
    Last edited by worthlutz; 21 Jan 2013 at 8:39 AM. Reason: left out "widget" in class definition

  2. #2
    Sencha User friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106

    Default

    Try changing your class definition's alias to look like this:

    Code:
    Ext.define('MyApp.view.MyClass', {
        extend: 'Ext.tree.panel',
        alias: 'widget.mytreepanel'
        <...>
    });
    Note the 'widget' prefix on the alias.

  3. #3
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Hillsborough, NC
    Posts
    429
    Answers
    3

    Default

    Quote Originally Posted by friend View Post
    Try changing your class definition's alias to look like this:

    Code:
    Ext.define('MyApp.view.MyClass', {
        extend: 'Ext.tree.panel',
        alias: 'widget.mytreepanel'
        <...>
    });
    Note the 'widget' prefix on the alias.
    You've got good eyes! But that was a typo on my part. My actual code has the "widget" part. It won't work without it. I've fixed it above.

    Worth

  4. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585

    Default

    What happens if you run the component query without creating the trees in the tab panel? At what point does this mysterious extra tree turn up?

    Are there any clues if you inspect this extra tree in the debugger, such as a rendered el or an ownerCt?

    Cut back the example, tweak it in various ways. Try to understand exactly what scenarios cause the extra tree.

    The highly scientific approach of poking it with a stick goes a long way to understand things like this.

  5. #5
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Hillsborough, NC
    Posts
    429
    Answers
    3

    Default

    Quote Originally Posted by skirtle View Post
    ...
    Are there any clues if you inspect this extra tree in the debugger, such as a rendered el or an ownerCt?

    Cut back the example, tweak it in various ways. Try to understand exactly what scenarios cause the extra tree.

    The highly scientific approach of poking it with a stick goes a long way to understand things like this.
    Thanks for poking me with the stick!

    My test case is way to complex but I'm trying to understand the interactions between lots of parts. Your comment on ownerCt (it did not have one) clued me in to checking an unrelated area of the code where I found sometime in the past I had created an instance to check out something. Forgot to remove it.

    Thanks again,
    Worth

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •