PDA

View Full Version : reuse custom xtype



piccard
16 Jan 2012, 6:54 AM
Hello,

I'm working with the MVC-pattern, which works great so far. For example, I created a class for a chart und via the xtype I could reuse it without any problems.
But now I encountered a problem with interactive components.

I.e. I build a tree which is bind to a store. So far, so good.



Ext.define('DW.view.navigation.nodes.NodesTree', {
extend: 'Ext.tree.Panel',
alias: 'widget.nodestree',

initComponent: function() {

console.log('initComponent: DW.view.navigation.nodes.NodesTree');

Ext.apply(this, {
rootVisible: false,
frame: false,
useArrows: true,
store: 'nodes.NodesTree'
});

this.callParent(arguments);
}
});


items : [{
margin: '0 5 5 0', // top right bottom left
xtype: 'nodestree',
flex: 1
}]

So, I just wanted to reuse this one, but when I rebind the component in a panel the component acts weird, like it's one and the same.

My question is now, how I could accomplish it to reuse these components, i.e. the same tree bind to the same store, without reprogramming it.

I think there should be a simple answer???

mitchellsimoens
16 Jan 2012, 9:25 AM
Is the root ont he tree store defined within the constructor or as a property?

piccard
17 Jan 2012, 5:29 AM
the root is defined in the cronstructor. So if it helps, here are some code-snippets:


Ext.define('DW.store.nodes.NodesTree', {
extend: 'Ext.data.TreeStore',
constructor: function() {
console.log('constructor: DW.store.nodes.NodesTree');
config = Ext.apply(this,{
proxy: {
type: 'ajax',
url: 'data/nodesTree.json'
},
reader: {
type: 'json'
},
root: {
text: '.',
expanded: true
},
folderSort: true,
sorters: [{
property: 'leaf',
direction: 'ASC'
}, {
property: 'text',
direction: 'ASC'
}]
});



this.callParent(arguments);

}


});



[
{
text: 'lu64rup',
expanded: true,
checked: false,
children: [
{
text: 'Node01',
id: '111',
leaf: true,
checked: false
},
{
text: 'Node02',
id: '222',
leaf: true,
checked: false
},
{
text: 'Node03',
id: '333',
leaf: true,
checked: false
}
]
}, ...

View-code is already above. So, is it maybe at all necassary to exchange the store for using the same component/tree?

thank you :-D