简体   繁体   English

如何在 Extjs 的卡片布局上获取当前活动项目的索引号(而不是活动项目的 ID)?

[英]How to get currently active item`s index number (and not active item`s id) on a card layout on Extjs?

How do I get the currently active item's index number (and not active item's id) on a card layout?如何在卡片布局上获取当前活动项目的索引号(而不是活动项目的 ID)? The following code will return active item's id:以下代码将返回活动项目的 id:

     Ext.getCmp('my-wizard').getLayout().activeItem.id];

What if I don't want to define an id for my component items and I just want to access active item's index number?如果我不想为我的组件项定义一个 id 而我只想访问活动项的索引号怎么办?

I couldn't find a built-in quick and easy way, but the following would work:我找不到内置的快速简便的方法,但以下方法可行:

var wiz = Ext.getCmp('my-wizard');
var activeItem = wiz.getLayout().activeItem;
var activeIndex = wiz.items.indexOf(activeItem);

If this was something that you wanted to do often, you could add it to the CardLayout prototype:如果这是您经常想做的事情,您可以将其添加到CardLayout原型中:

Ext.override(Ext.layout.CardLayout, {
    getActiveIndex: function() {
        return this.container.items.indexOf(this.activeItem);
    }
});

Then you could use it with:然后你可以使用它:

var activeIndex = Ext.getCmp('my-wizard').getLayout().getActiveIndex();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM