如何以编程方式触发面板上的事件?

发布于 2024-10-06 02:13:33 字数 1438 浏览 0 评论 0原文

我有以下菜单。

用户单击面板的标题,中间的区域会发生变化,这是有效的。

但是,我总是想以编程方式单击面板,例如,以便我可以在打开面板的文本中创建超链接,就像用户单击它们一样。

如何以编程方式触发手风琴菜单中面板上的单击事件,如下所示:

Ext.select('span#internal_link_001').on('click', function() {
    Ext.getCmp('panelApplication').trigger('click'); //error "trigger is not a function"
});

手风琴菜单代码:

Ext.onReady(function(){

    menuItemStart = new Ext.Panel({
        id: 'panelStart',
        title: 'Start',
        html: 'This is the start menu item.',
        cls:'menuItem'
    });

    menuItemApplication = new Ext.Panel({
        id: 'panelApplication',
        title: 'Application',
        html: 'this is the application page',
        cls:'menuItem'
    });

    menuItemModules = new Ext.Panel({
        id: 'panelModules',
        title: 'Modules',
        layout: 'card',
        html: 'this is the modules page',
        cls:'menuItem'
    });

    menuItemSettings = new Ext.Panel({
        id: 'panelSettings',
        title: 'Settings',
        layout: 'card',
        html: 'this is the settings page',
        cls:'menuItem'
    });

    var regionMenu = new Ext.Panel({
        region:'west',
        split:true,
        width: 210,
        layout:'accordion',
        layoutConfig:{
            animate:true
        },
        items: [ menuItemStart, menuItemApplication, menuItemModules, menuItemSettings ]
    });
    ....

I have the following according menu.

The user clicks on the headers of the panels and a region in the middle changes, that works.

However, I always want to programmatically click the panels, e.g. so that I can create hyperlinks in the text which open up panels, just as if the user clicked on them.

How can I trigger an event click programmatically on a panel in my accordion menu, something like this:

Ext.select('span#internal_link_001').on('click', function() {
    Ext.getCmp('panelApplication').trigger('click'); //error "trigger is not a function"
});

Accordion menu code:

Ext.onReady(function(){

    menuItemStart = new Ext.Panel({
        id: 'panelStart',
        title: 'Start',
        html: 'This is the start menu item.',
        cls:'menuItem'
    });

    menuItemApplication = new Ext.Panel({
        id: 'panelApplication',
        title: 'Application',
        html: 'this is the application page',
        cls:'menuItem'
    });

    menuItemModules = new Ext.Panel({
        id: 'panelModules',
        title: 'Modules',
        layout: 'card',
        html: 'this is the modules page',
        cls:'menuItem'
    });

    menuItemSettings = new Ext.Panel({
        id: 'panelSettings',
        title: 'Settings',
        layout: 'card',
        html: 'this is the settings page',
        cls:'menuItem'
    });

    var regionMenu = new Ext.Panel({
        region:'west',
        split:true,
        width: 210,
        layout:'accordion',
        layoutConfig:{
            animate:true
        },
        items: [ menuItemStart, menuItemApplication, menuItemModules, menuItemSettings ]
    });
    ....

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

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

发布评论

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

评论(1

以往的大感动 2024-10-13 02:13:33

为什么不使用适当的组件功能:

Ext.onReady(function(){

    menuItemStart = new Ext.Panel({
        id: 'panelStart',
        ...
    });

    menuItemApplication = new Ext.Panel({
        id: 'panelApplication',
        ...
    });

    menuItemModules = new Ext.Panel({
        id: 'panelModules',
        ...
    });

    menuItemSettings = new Ext.Panel({
        id: 'panelSettings',
        ...
    });

    var regionMenu = new Ext.Panel({
        ...
        layout:'accordion',
        items: [ menuItemStart, menuItemApplication, menuItemModules, menuItemSettings ]
    });

    Ext.select('span#internal_link_001').on('click', function() {
        regionMenu.getLayout().setActiveItem('panelApplication' /* use the ID or the numeric index */);
    });
}

Why don't you use the appropriate component features:

Ext.onReady(function(){

    menuItemStart = new Ext.Panel({
        id: 'panelStart',
        ...
    });

    menuItemApplication = new Ext.Panel({
        id: 'panelApplication',
        ...
    });

    menuItemModules = new Ext.Panel({
        id: 'panelModules',
        ...
    });

    menuItemSettings = new Ext.Panel({
        id: 'panelSettings',
        ...
    });

    var regionMenu = new Ext.Panel({
        ...
        layout:'accordion',
        items: [ menuItemStart, menuItemApplication, menuItemModules, menuItemSettings ]
    });

    Ext.select('span#internal_link_001').on('click', function() {
        regionMenu.getLayout().setActiveItem('panelApplication' /* use the ID or the numeric index */);
    });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文