PDA

View Full Version : Using Refs instead of Items



jpcook01
17 Oct 2012, 4:56 AM
Hello,

I have the following viewport:


Ext.create('Ext.container.Viewport', {
disabled: true,
id: 'viewport',
layout: 'border',
items: [{
id: 'sitemaptree',
xtype: 'sitemaptree',
title: 'Sitemap',
region: 'west',
width: 550,
split: true,
margins: '5 0 5 5'
},{
title: 'Details',
id: 'nodedetailspanel',
itemId: 'maindetails',
region: 'center',
margins: '5 0 5 5',
hidden: true,
items: [{
height: 540,
columnWidth: 0.4,
margin: '0 0 0 10',
xtype: 'fieldset',
title: 'Navigation Node',
defaults: {
width: 540,
labelWidth: 150,
anchor: '100%'
},
defaultType: 'textfield',
items: [{
id: 'nodedetailsform',
xtype: 'nodedetailsform'
}, {
id: 'digitextnodedetailsform',
xtype: 'digitextnodedetailsform'
}
]
}]
}]

});


The nodedetailspanel contains two items. nodedetailsform and digitextnodedetailsform. In order to display either one of these items dynamically I have the following function.




onSitemapTreeSelect: function(tree, record, index, eOpts) {
var sitemapStore = this.getSitemapStore();

if(sitemapStore.isDigiText()) {
Ext.getCmp('digitextnodedetailsform').loadForm(record);
Ext.getCmp('digitextnodedetailsform').show();
Ext.getCmp('nodedetailspanel').show();
Ext.getCmp('nodedetailsform').hide();
} else {
Ext.getCmp('nodedetailsform').loadForm(record);
Ext.getCmp('nodedetailsform').show();
Ext.getCmp('nodedetailspanel').show();
Ext.getCmp('digitextnodedetailsform').hide();
}

},


This is a bit messy and I wondered if swapping the items array with the 2 form items to refs would be a better solution and make the above function much neater?

Thanks
Jon

mitchellsimoens
22 Oct 2012, 9:07 AM
I don't see any benefit of using refs in this case, they are used to hold on to global views where that's not really what you are doing. show/hide is fine or add/remove