PDA

View Full Version : MVC - using several instances of views that need a controller



chaostimmy
31 Jul 2012, 5:36 AM
Heya,
I'm currently writing an application using the Extjs MVC structure.

Now I have the problem, that I need more than one instance of an specific view that also needs an controller... Due the fact that my controllers get the view instance they're "controlling" with the REF method by the views itemId.

So what's the way to handle that?
here an example that (hopefully) describes my problem:


Ext.define('Myapp.controller.AnyController', {
extend: 'Ext.app.Controller',
refs: [{
selector: '#anyView',
ref: 'anyView'
}, {
selector: '#anyView #anyButton',
ref: 'anyButton'
}],
init: function () {
this.control({
'#anyView #anyButton': {
click: this.onClickAnyButton
}
});
},
onClickAnyButton: function () {
//do anything
}
});

Ext.define('Myapp.view.AnyView', {
extend: 'Ext.window.Window',
alias: 'widget.anyView',
itemId: "anyView",
config: {
name: ''
},
constructor: function (config) {
this.initConfig(config);
this.callParent(arguments);
},
initComponent: function () {
Ext.applyIf(this, {
title: 'winow title',
items: [{
xtype: 'button',
itemId: 'anyButton'
}]
});
}
});


Ext.Loader.setConfig({
enabled: true,
paths: {
Myapp: 'myappfolder/app'
}
});
Ext.define('Silva.Application', {
extend: 'Ext.app.Application',
requires: [
'Myapp.view.AnyView'
],
controller: [
'Myapp.controller.AnyController'
]
constructor: function (config) {
this.autoCreateViewPort = false;
this.appFolder = Ext.Loader.getPath("Myapp");
this.callParent(arguments);
}
launch: function () {
renderTo: 'MyAppDiv',
items: [{
xtype: 'anyView',
name: 'any view with config'
}, {
xtype: 'anyView2',
name: 'any view with another config'
}, {
xtype: 'anyView3',
name: 'any view with a real different config'
}]
}