Ext.define('DigitalPaper.controller.Documents', {
extend: 'Ext.app.Controller',
views: ['Documents'],
stores: ['Documents'],
models: ['Documents'],
init: function() {
console.log('[OK] Init Controller: Documents');
}
});
What's the function to get Model or View of this controller? I've tried
Ext.getModel('Documents');
this.getModel('Documents');
this.getModel();
this.getDocumentsModel();
Any suggests?
Solution Found:
In the Controller it is possible to use the reference to the View:
refs: [{
ref: 'viewDocuments', // will be create the method this.getViewDocuments();
selector: 'Documents'
}],
So you can get the View with this:
this.getViewDocuments();
Ext controllers are pretty weird, in that there is a single instance of a given controller, no matter how many related view instances you might have. In most MVC or MVP systems there is one controller instance per view instance.
If you plan to use multiple view instances, then you should not keep references to those views in the controller.
You might want to look into Deft's MVC extension for ExtJs that has one controller instance per view instance (plus dependency injection):
http://deftjs.org/
Anyways, controller.getView() returns a reference to the view CLASS, not an object instance. Same with getModel(). getStore() DOES return a store instance.
In your controller, you can do something like this:
this.viewInstance = this.getDocumentsView().create();
I would also recommend naming your model in the singular. It is not a Documents. It is a Document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With