【问题标题】:ExtJS 4: Where should view events live if not using ExtJS MVC architecture?ExtJS 4:如果不使用 ExtJS MVC 架构,应该在哪里查看事件?
【发布时间】:2012-07-18 23:07:25
【问题描述】:

当使用 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();
    }

});

【问题讨论】:

    标签: events extjs grid


    【解决方案1】:

    它们应该存在于组件(实际上是 Observable)的 listeners 属性中,如下所示:

    http://jsfiddle.net/3LCm4/7/

    文档:

    http://docs.sencha.com/ext-js/4-1/#!/api/Ext.util.Observable-cfg-listeners

    【讨论】:

    • 为什么这段代码在 Mozilla Firefox 中不起作用?它适用于谷歌浏览器。
    • firefox 不喜欢没有参数的 alert() :) 修复了它。
    猜你喜欢
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    • 2012-01-02
    相关资源
    最近更新 更多