PDA

View Full Version : Cannot get View instance from the controller



jfarribillaga
31 Jul 2013, 7:13 AM
Hi folks,

In my app, I'm using ExtJS 4.2.1 and I have a viewport with one item, a main view, which it is a simple class extending from Ext.container.Container.

I have a main controller too, and I'm trying to get the view instance, so dynamically I can push the corresponding items if the user is logged or not.

I've tried using views: ['MainView'], refs[ { selector: 'thextype' }], etc with no luck.

I was using the reference (ref) in sencha touch to do this kind of things, can you help me with Extjs v4.2 ?

Just for clarification, I'm not trying to get the DOM element, I'm trying to get the view instance with the associated methods.

Thanks in advance,

Juan.-

tobiu
31 Jul 2013, 4:53 PM
where and how do you try to get your components?



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

refs: [{
ref: 'list',
selector: 'grid'
}],

init: function() {
this.control({
'button': {
click: this.refreshGrid
}
});
},

refreshGrid: function() {
this.getList().store.load();
}
});


you can use your custom xtypes inside this.control.
the getters for refs also work.

the only difference to touch is that you can not use refs inside the this.control - queries.

best regards
tobiu

jfarribillaga
1 Aug 2013, 6:10 AM
Hi Tobiu,

First of all, thanks for your quick response.
I know the limitations about the control and the lack of use references. What I'm trying to do is something like:


Ext.define('MyApp.view.MainView', {
extend: 'Ext.container.Container',

alias: 'widget.mainContainer',

cls: ['mainContainer'],

items: [
{
xtype: 'panel',
items: [
{
html: "my view"
}
]
}
]
});




Ext.define('MyApp.controller.MainController', {
extend: 'MyApp.controller.BaseController',


refs: [
{
ref: 'mainContainer',
selector: 'mainContainer'
}
],


init: function() {
this.getApplication().on({
openDashboard: this.onOpenDashboard
});
},
onOpenDashboard: function() {
var mainContainerView = this.getMainContainer();
mainContainerView.showSomething(); //mainContainerView should be an instance of the view.
}
});




Where, openDashboard event is fired if after a login success.


Can you follow me?

Best,

Juan.-

jfarribillaga
2 Aug 2013, 11:22 AM
Hi guys,

After some time debugging, it seems the problem was the context where it was being called the function.

I've added in the init method a line like:

var openCrmDashboardFn = Ext.Function.bind(this.onOpenCrmDashboard, this);

and it worked.

BTW, about the impossibility to use refs into the controls, Do you know if there is an ETA to add it to ExtJS ?

Thanks for your help