PDA

View Full Version : Why does Controller.getRef only return first item?



KajaSheen
20 Jun 2012, 12:48 AM
My controller manages multiple instances of the same view (which are windows, that can be open simultaniously)... Now I have a ref in my controller that points to that component, and I wanted to implement a "Close all" function. I noticed that the component query always returns only a single element. While this ist not a bug, it could be nice to have a configuration option in the refs, that allows to return an array from the component query.



Ext.define('AM.controller.Users', {
extend: 'Ext.app.Controller',

stores: ['Users'],

models: ['User'],

views: ['user.Edit'],

refs: [
{
ref: 'editFormsRef',
selector: 'useredit'
}
],

init: function() {
this.control({
'viewport > userlist button[action=closeall]': {
click: this.closeAllForms
}
});
},

closeAllForms: function() {

var window = this.getEditFormsRef();
while(Ext.isDefined(window)) {
window.close();
window = this.getEditFormsRef();
}

}
});


A much simplier solution would be



{
ref: 'editFormsRef',
selector: 'useredit',
type: 'array' //or something else
}
[...]
closeAllForms: function() {
Ext.each(this.getEditFormsRef(), function(form) {form.close();});
}


I guess I could write a patch for the controller later on, if there is someone interested in this?