得到我的tabpanel组件,但不能使用添加添加一个选项卡

Get my tabpanel component but cant use add to add a tab

本文关键字:添加 一个 选项 tabpanel 我的 组件 但不能      更新时间:2023-09-26

我有一个tabpanel在视图makmoney .js。我想在控制器addtab。js中写代码。但是我在我的chrome控制台遇到了一个错误。

和我发现Ext.ComponentQuery.query('itemId')[0]返回类型是组件,但tabpanel的添加方法必须使容器。添加容器。这是原因吗?如果正确,我可以修改什么

my makmoney .js code:

Ext.define('ylp2p.view.makemoney',{
extend: 'Ext.Panel',
xtype: 'makemoney',
requires: [
    'Ext.Toolbar',
    'Ext.tab.Panel'
],
config:{
    layout: 'vbox',
    items:[
        {
            xtype: 'toolbar',
            docked: 'top',
            title: '111'
        },
        {
            xtype: 'tabpanel',//-----here is my tappanel
            itemId: 'tabfirst',
            flex: 1,
            tabBar: {
                layout: {
                    pack: 'center'
                }
            }
        }
    ]
}
});

和控制器代码:

Ext.define('ylp2p.controller.addtab',{
extend: 'Ext.app.Controller',
launch: function(){
    var moneytab = Ext.ComponentQuery.query('.makemoney #tabfirst')[0];
    //i think i get the component alerdy
    var myPanel = Ext.create('Ext.Panel', {
        html: 'This will be added to a Container'
    });
    //and write a panel
    moneytab.add([myPanel]);
    //make the panel into the tap.i dont why it not work
}
});

my console in chrome put an error:

Uncaught Error: [ERROR][Ext.Container#doAdd] Adding a card to a tab container without specifying any tab configuration

会成功的

var moneytab = Ext.ComponentQuery.query('makemoney #tabfirst')[0];
    var myPanel = Ext.create('Ext.Panel', {
        html: 'This will be added to a Container',
        title: 'Yourtitle'
    });
    //and write a panel
    moneytab.add(myPanel);

您的选择器不正确,这就是错误的原因。

var moneytab = Ext.ComponentQuery.query('.makemoney #tabfirst')[1];

moneytab = undefined;

用这个代替:

var moneytab = Ext.ComponentQuery.query('tabpanel #tabfirst')[0];