As with so many things in ExtJS, the ‘ref’ option introduced in 3.0 is not very well documented, at least as far as I can tell. Which is unfortunate, because it’s extremely useful, and drastically reduces the need for ids. Here’s an example of how to use it:
Ext.onReady(function() {
Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';
Ext.QuickTips.init();
// Define a simple component
MyComponent = Ext.extend(Ext.form.FormPanel, {
frame: true,
initComponent: function() {
var config = {
items: [{
xtype: 'textfield',
fieldLabel: 'Name'
}, {
xtype: 'textfield',
fieldLabel: 'Address'
}],
bbar: ['->', {
text: 'Cancel',
minWidth: 100,
ref: '../cancelButton'
}, {
text: 'Save',
minWidth: 100,
ref: '../saveButton'
}]
};
Ext.apply(this, Ext.apply(this.initialConfig, config));
MyComponent.superclass.initComponent.apply(this, arguments);
}
});
Ext.reg('my_component_xtype', MyComponent);
// Create a display a window with the panel in it...
var w = new Ext.Window({
modal: true,
items: {
xtype: 'my_component_xtype',
title: 'Panel 1',
ref: 'theFormPanel'
}
});
w.show();
// See how we can use the references...
w.theFormPanel.saveButton.on('click', function() {
console.log('Save was clicked');
}, this);
console.log(w.theFormPanel.title);
});

Leave a comment