PDA

View Full Version : problem with trees sharing same store



billtricarico
21 Dec 2011, 11:14 PM
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.

mitchellsimoens
22 Dec 2011, 11:30 AM
Are you using Ext.define to create your own extension? If you are you should not do this:


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:


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.

billtricarico
22 Dec 2011, 11:49 AM
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?

mitchellsimoens
22 Dec 2011, 11:51 AM
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.

xbral
12 Mar 2014, 3:45 AM
Thanks, It's work to me....