javascript 更改卡片布局中的活动项目。扩展程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5383301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 17:01:05  来源:igfitidea点击:

change active item in a card layout. ExtJS

javascriptasp.netc#-4.0extjs

提问by MBU

I have a panel using the card layout as follows:

我有一个使用卡片布局的面板,如下所示:

var cardpanel = new Ext.Panel(
{
    id: 'cardPanel',
    //title: 'Card Layout',
    region: 'center',
    layout: 'card',
    activeItem: 0,
    autoDestroy: false,
    bodyStyle: 'border-top:0px',
    defaults: {
        border: false
    },
    items: [mediaGrid, mappanel],
    tbar: [
        {
            id: 'card-media',
            text: 'Media',
            icon: '/img/silk/images.png',
            width: 50,
            handler: function () {
                //switch to media
            }
        },
        {
            id: 'card-map',
            text: 'Map',
            icon: '/img/silk/map.png',
            width: 50,
            handler: function () {
                //switch to map
            }
        }
    ]
});

The commented parts are where i would like to implement the switch between the 2 panels in the card layout but im not sure how to do that. I've tried using setActiveItem but I was always either getting the setActiveItem is not a function or it it just didnt say anything. How do i get it to switch panels?

评论部分是我想在卡片布局中实现两个面板之间切换的地方,但我不知道如何做到这一点。我试过使用 setActiveItem 但我总是要么得到 setActiveItem 不是一个函数,要么它什么也没说。我如何让它切换面板?

回答by Jason Harwig

You can only use thisif you are in a handler for cardpanel.

this当您在 cardpanel 的处理程序中时才能使用。

cardpanel.layout.setActiveItem(0); // to switch to mediaGrid
cardpanel.layout.setActiveItem(1); // to switch to mappanel

回答by Robby Pond

You need to call

你需要打电话

this.layout.setActiveItem();

in handler and add

在处理程序中并添加

scope: cardpanel

under the handler definition.

在处理程序定义下。

回答by Abdel Raoof

You get the "setActiveItem is not a function" because the object with which you are calling the method do not have the function. In short you are using the wrong object to call the setActiveItem method. You need to modify your code as:

您得到“setActiveItem 不是函数”,因为您调用该方法的对象没有该函数。简而言之,您使用错误的对象来调用 setActiveItem 方法。您需要将代码修改为:

{
            id: 'card-media',
            text: 'Media',
            icon: '/img/silk/images.png',
            width: 50,
            scope: this,
            handler: function () {
                this.layout.setActiveItem('card-map');
            }
        },
        {
            id: 'card-map',
            text: 'Map',
            icon: '/img/silk/map.png',
            width: 50,
            scope: this,
            handler: function () {
                this.layout.setActiveItem('card-media');
            }
        }