当使用 Sencha ExtJS 框架时,您的视图的事件存在于该视图的控制器内部。如果您不使用控制器,您将事件存储在哪里。
例如,假设我们的 MVC 应用程序,我们有一个用户网格(用户列表),我们有一个事件“itemdblclick”。我们将如何在非 MVC 应用程序中实现“itemdblclick”?
Ext.define('AM.view.user.List' ,{
extend: 'Ext.grid.Panel',
alias: 'widget.userlist',
title: 'All Users',
// we no longer define the Users store in the `initComponent` method
store: 'Users',
...
});
Ext.define('AM.controller.Users', {
extend: 'Ext.app.Controller',
stores: ['Users'],
models: ['User'],
views: [
'user.List',
'user.Edit'
],
init: function() {
this.control({
'viewport > userlist': {
itemdblclick: this.editUser
},
'useredit button[action=save]': {
click: this.updateUser
}
});
},
editUser: function(grid, record) {
var view = Ext.widget('useredit');
view.down('form').loadRecord(record);
},
updateUser: function(button) {
console.log('clicked the Save button');
var win =
button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();
record.set(values);
win.close();
// synchronize the store after editing the record
this.getUsersStore().sync();
}
});