如何使用控制器来控制extjs4中的菜单

发布于 2024-12-05 02:25:25 字数 2195 浏览 2 评论 0原文

我正在尝试使用 extjs4 MVC 构建 CRM Web 应用程序。 在设计了一个简单的网页后,我尝试使用控制器来控制左侧面板上的菜单。 但控制器对我来说太难理解了。

由于UI设计上的一些原因,菜单树面板的外部有一个面板。

这是我的代码。

app/view/MenuBar.js

Ext.define('Crm.view.MenuBar',{
    extend: "Ext.panel.Panel",
    alias: 'widget.crm_menubar',
    requires: ['Crm.store.Menus'],
    initComponent: function(){
    var store = Ext.create('Crm.store.Menus');
    Ext.apply(this,{
        xtype:'panel',  
        title: "menu"
        width: 212,
        frame:true,
        hideCollapseTool:true,
        split: true,
        collapsible:true,
        collapseMode: 'mini',
        items: [
            Ext.create('Ext.tree.Panel',{
                id: 'menutree',
                border: false,
                height: '100%',
                rootVisible: false,
                store: store
            })
        ]
    });
    this.callParent();
    }
});

app/store/Menus.js

Ext.define('Crm.store.Menus',{
    extend: 'Ext.data.TreeStore',
    root: {
            expanded: true, 
            children: [
                {   text: "subrootitem1",
                    expanded: true,
                    children:[
                    { id: 'a', text: "item1", leaf: true},
                    { id: 'b', text: "item2", leaf: true },
                    ]
                },
                {   text: "subrootitem2", 
                    expanded: true, children: [
                        { id: 'c', text: "item1", leaf: true },
                        { id: 'd', text: "item2", leaf: true}
                    ]
                }
            ]
        }
});

app/controller/Menu.js

Ext.define('Crm.controller.Menu',{
    extend: 'Ext.app.Controller',
    refs: [{ref: 'menubar', selector: 'crm_menubar'}],
    init: function(){
        alert('test'); // this line can already execute when page is loading  
        this.control({
            'crm_menubar': {
                itemmousedown: this.onItemClicked
            }
        });
    },
    onItemClicked: function(){
        alert('clicked');
    }
});

我想与菜单交互。但是这一行的代码不起作用。 最后,“裁判”变得模糊不清。你能给我一些解决方案吗

I am trying to build a CRM web application using extjs4 MVC.
After design a simple web page, I try to use controller to control the menu on the left panel.
But the controller is so difficult to understand for me.

Because of some reasons on ui design, there is a panel in the outer of the menu tree panel.

Here is my code.

app/view/MenuBar.js

Ext.define('Crm.view.MenuBar',{
    extend: "Ext.panel.Panel",
    alias: 'widget.crm_menubar',
    requires: ['Crm.store.Menus'],
    initComponent: function(){
    var store = Ext.create('Crm.store.Menus');
    Ext.apply(this,{
        xtype:'panel',  
        title: "menu"
        width: 212,
        frame:true,
        hideCollapseTool:true,
        split: true,
        collapsible:true,
        collapseMode: 'mini',
        items: [
            Ext.create('Ext.tree.Panel',{
                id: 'menutree',
                border: false,
                height: '100%',
                rootVisible: false,
                store: store
            })
        ]
    });
    this.callParent();
    }
});

app/store/Menus.js

Ext.define('Crm.store.Menus',{
    extend: 'Ext.data.TreeStore',
    root: {
            expanded: true, 
            children: [
                {   text: "subrootitem1",
                    expanded: true,
                    children:[
                    { id: 'a', text: "item1", leaf: true},
                    { id: 'b', text: "item2", leaf: true },
                    ]
                },
                {   text: "subrootitem2", 
                    expanded: true, children: [
                        { id: 'c', text: "item1", leaf: true },
                        { id: 'd', text: "item2", leaf: true}
                    ]
                }
            ]
        }
});

app/controller/Menu.js

Ext.define('Crm.controller.Menu',{
    extend: 'Ext.app.Controller',
    refs: [{ref: 'menubar', selector: 'crm_menubar'}],
    init: function(){
        alert('test'); // this line can already execute when page is loading  
        this.control({
            'crm_menubar': {
                itemmousedown: this.onItemClicked
            }
        });
    },
    onItemClicked: function(){
        alert('clicked');
    }
});

I want interact with the menu. But the code up this line do not work.
At last the 'refs' is obscure. Can you give me some solution

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀梦 2024-12-12 02:25:25

尝试将您的控制器注册到树面板:

this.control({
    'crm_menubar treepanel[id="menutree"]': {
        itemclick: this.onItemClicked,
        scope : this
    }
});

Try registering your controller to the treepanel:

this.control({
    'crm_menubar treepanel[id="menutree"]': {
        itemclick: this.onItemClicked,
        scope : this
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文