javascript - ExtJS 4.1 Controller 处理树节点点击事件

标签 javascript extjs controller treepanel

遇到问题并且不确定如何进行调试。发现了一个与我的几乎一模一样的问题,但解决方案不起作用:How to catch tree node clicks from a (MVC) controller in ExtJs 4?

我在这个问题和我的问题之间看到的唯一区别是,我的树是使用 treepanelxtype 直接在我的布局中作为项目对象创建的,其中那个是单独创建。

这是我的 Controller :

Ext.define("IOL.controller.app.AppLayout", {
    extend: 'Ext.app.Controller',
    init: function() {
        this.control({
            'app toolbar > button[itemId=filter]' : {
                click: this.onFilter
            },
            'menuTree': {
                itemclick: this.onFilter
            }
        });
    },

    onFilter: function(btn) {
        alert('test');
        Ext.create('IOL.view.app.Home').show();
    }

});

这是我认为的相关项目:

{
        xtype: 'treepanel',
        title: 'Navigation',
        split: true,
        collapsible: true,
        margins: '5 0 5 5',
        region: 'west',
        width: 170,
        id: 'menuTree',
        alias: 'widget.menuTree',
        store: Ext.create('IOL.store.app.AppNav'),
        useArrows: true,
        rootVisible: false
        /*listeners : {
            itemdblclick : function(view,rec,item,index,eventObj) {

                console.log(view);
                console.log(rec);
                console.log(item);
                console.log(index);
                console.log(eventObj);
                if(rec.get('leaf') == true){
                    Ext.ComponentQuery.query('tabpanel')[0].add({
                        xtype: 'panel',
                        title: rec.get('text'),
                        itemId: rec.get('id'),
                        //url: 'server/HomeTab/read.php',
                        html : 'test content name: ' + rec.get('id'),
                        closable : true
                    });
                }

            }
        }*/
    }

按钮 app toolbar > button[itemId=filter] 的控件有效,但是将相同的操作分配给“menuTree”不起作用。浏览器控制台使用 Ext.getCmp('menuTree') 返回一个有效对象,所以我不知道为什么 Controller 似乎没有作用于树。

这棵树是从商店加载的,这让我想知道这是否与需要使用 .on('click') 而不是 .click( ) 在 jQuery 中...几乎就像 Controller 没有看到树(但在同一 View 中看到按钮?)。我特意直接在树上注释掉了处理程序(这确实有效)。

如果有帮助,可以提供所有文件。

最佳答案

Ext.getCmp() 通过 id 返回组件,而 Controller 使用 Ext.ComponentQuery.query() 语法来查找它们的组件;如此有效,您正在尝试使用不存在的 xtype menuTree 来控制组件。您应该使用“#menuTree”或“treepanel”作为选择器。

关于javascript - ExtJS 4.1 Controller 处理树节点点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12114786/

相关文章:

javascript - 创建对象的正确方法

php - 使用 php 的简单 Extjs gridpanel 实现

ExtJS 4 : Adding a button to a tab panel header

java - Servlet异常: No adapter for handler just for one service

适用于通用 (iPhone/iPad) 应用程序的 iOS Controller

php - Laravel 5 - 更改默认登录操作

javascript - Google Javascript 客户端库 OAUTH 请求离线访问权限,但从未请求过

javascript - 如何在浏览器上使用手机麦克风录音?

javascript - this.up() 不是函数 EXTJS

javascript - 在循环中添加div jquery