0

我想在 Controller.like http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Controller上的插件中添加事件侦听 器使用组件查询获取插件似乎不同于正常成分。是否可以使用组件查询从组件中获取插件?

这是我的组件

Ext.define('App.view.file.List',{
     rootVisible: false, 
     extend:'Ext.tree.Panel',
     alias:'widget.filelist',
     viewConfig: {
        plugins: {
            ptype: 'treeviewdragdrop', 
            allowParentInsert:true 
        }
    },
    //etc ...

我可以使用组件查询获取treeviewdragdrop插件吗

Ext.define('App.controller.FileManagement', {
    extend:'Ext.app.Controller',
    stores:['Folder'],
    views:['file.List','file.FileManagement'],
    refs:[
        { ref:'fileList', selector:'filelist' }
    ],
    init:function () {
        this.control({  
            'filelist > treeviewdragdrop':{drop:this.drop}  // <-- here is selector
        });
    },
    // etc ....
4

2 回答 2

4

你不能因为插件不是组件,因此没有选择器会找到它。

Also, the drop event is fired by the treeview, so the treeview is really what you want to hook to.

This will work:

init:function () {
    this.control({  
        'filelist > treeview': {drop:this.drop}
    });
},
于 2012-06-06T14:49:54.430 回答
2

没有直接的方法可以做到这一点。如果我站在你的立场上,我可能会在插件触发其事件时让树触发所需的事件:

// view
Ext.define('App.view.file.List',{
     // ...
     viewConfig: {
        plugins: {
            ptype: 'treeviewdragdrop',
            pluginId: 'treeviewdragdrop', // <-- id is needed for plugin retrieval
            allowParentInsert:true 
        }
    },
    initComponent: funcion() {
      var me = this;
      me.addEvents('viewdrop');
      me.callParent(arguments);
      me.getPlugin('treeviewdragdrop').on('drop', function(node, data, overModel, dropPosition, eOpts) {
        // when plugin fires "drop" event the tree fires its own "viewdrop" event
        // which may be handled via ComponentQuery
        me.fireEvent('viewdrop', node, data, overModel, dropPosition, eOpts);
      });
    },
    // ...

控制器:

// controller
Ext.define('App.controller.FileManagement', {
    // ...
    init:function () {
        this.control({  
            'filelist':{viewdrop:this.drop}  // <-- here is selector
        });
    },
    // etc ....
于 2012-06-06T14:08:15.827 回答