1. #1
    Sencha User
    Join Date
    May 2010
    Location
    Las Vegas, NV
    Posts
    133
    Answers
    7
    Vote Rating
    2
    billtricarico is on a distinguished road

      0  

    Default Unanswered: problem with trees sharing same store

    Unanswered: problem with trees sharing same store


    Hello,

    I have created two trees that share the same treestore. I would expect both trees to behave the same, but they do not. What I am seeing is that one tree tends to get duplicate nodes as I expand/collapse, and the other tree does not get any when I expand/collapse the parallel node. After that, neither tree renders correctly.

    Essentially I have the same tree rendered on two different tabs. Best practices suggest using the same store since the trees are the same. What do I have to do to keep these trees working correctly?

    Thanks.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,522
    Answers
    3447
    Vote Rating
    814
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Are you using Ext.define to create your own extension? If you are you should not do this:

    Code:
    Ext.define('MyTree', {
        extend : 'Ext.tree.Panel',
        alias  : 'widget.mytree',
    
        store : Ext.create('MyTreeStore'),
    
        ...
    });
    That store will be shared among all instances. You should to something like this instead:

    Code:
    Ext.define('MyTree', {
        extend : 'Ext.tree.Panel',
        alias  : 'widget.mytree',
    
        initComponent: function() {
            Ext.apply(this, {
                 store : Ext.create('MyTreeStore')
            });
    
             this.callParent(arguments);
        }
    
        ...
    });
    Now for each instance a new store will be created.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    May 2010
    Location
    Las Vegas, NV
    Posts
    133
    Answers
    7
    Vote Rating
    2
    billtricarico is on a distinguished road

      0  

    Default


    I am using Ext Desiger, so the first code sample looks like what Designer is generating. The only difference is that the store is referenced by id, not Ext.create('MyTreeStore').

    I see you said "Now for each instance a new store will be created." Is that what I really want? Two independent stores instances? I want the two trees to share the same store instance. So they are both in sync in case the underlying tree structure is changed. Is that possible?

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,522
    Answers
    3447
    Vote Rating
    814
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Isn't that what you are asking about... they share the same store so things will act funny if two active components use the same store. Using an id is just sharing the same store.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Jun 2013
    Posts
    1
    Vote Rating
    0
    xbral is on a distinguished road

      0  

    Default Great code

    Great code


    Thanks, It's work to me....

Thread Participants: 2