Crockford
3 Sep 2011, 1:26 PM
MVC: move logic from "view" to "controller"
Hi everyone.
I have some issues trying to move logic from a view to a controller
This is my View
Ext.define('Mvc.test.view.MainMenuList', {
extend: 'Ext.view.View',
alias: 'widget.mainmenulist',
store: 'Mvc.test.store.MenuList',
tpl: new Ext.XTemplate('<tpl for="."><div class="menuItem menuItem{pk}"><span>{title}</span></div></tpl>'),
itemSelector: 'div.menuItem',
listeners: {
itemclick: function (el, objModel, node) {
console.log(el);
}
}
});
I have added a event manager for the "itemclick" event and it works well.
I don't like it. It would be cool if I could move it to a controller.
I have done this:
Ext.define('Mvc.test.controller.MenuController', {
extend: 'Ext.app.Controller',
views: ['Mvc.test.view.MainMenuList'],
init: function () {
this.control({
'mainmenulist': { //<-- HERE! What must I use as component query?
click: function () { console.log('click event raised'); }
}
});
}
});
The event click is never raised. Do you have some suggestion?
Hi everyone.
I have some issues trying to move logic from a view to a controller
This is my View
Ext.define('Mvc.test.view.MainMenuList', {
extend: 'Ext.view.View',
alias: 'widget.mainmenulist',
store: 'Mvc.test.store.MenuList',
tpl: new Ext.XTemplate('<tpl for="."><div class="menuItem menuItem{pk}"><span>{title}</span></div></tpl>'),
itemSelector: 'div.menuItem',
listeners: {
itemclick: function (el, objModel, node) {
console.log(el);
}
}
});
I have added a event manager for the "itemclick" event and it works well.
I don't like it. It would be cool if I could move it to a controller.
I have done this:
Ext.define('Mvc.test.controller.MenuController', {
extend: 'Ext.app.Controller',
views: ['Mvc.test.view.MainMenuList'],
init: function () {
this.control({
'mainmenulist': { //<-- HERE! What must I use as component query?
click: function () { console.log('click event raised'); }
}
});
}
});
The event click is never raised. Do you have some suggestion?