autoDestroy的行为:Extjs4中为false [英] Behaviour of autoDestroy: false in Extjs4

查看:117
本文介绍了autoDestroy的行为:Extjs4中为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

autoDestroy:false在Ext-Js 4中实际上如何工作. 我打算关闭选项卡,然后单击按钮重新创建它,请参见此处的代码:

How does autoDestroy:false actually works in Ext-Js 4. I am intending to close the tab and then recreate it on click of button, See the code here:

    <html>
    <head>
     <link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css" />
     <script type="text/javascript" src="../bootstrap.js"></script>
     <script type="text/javascript">Ext.require('Ext.tab.*');

    Ext.onReady(function(){

var tabs = Ext.create('Ext.tab.Panel', {
    width: 400,
    height: 400,
    renderTo: document.body,
    autoDestroy: false,
    items: [{
        title: 'Home',
        html: 'Home',
        itemId: 'home'

    }, {
        title: 'Tickets',
        html: 'Tickets',
        itemId: 'tickets',
        closable: true,
        closeAction: 'hide'
    }]
});

Ext.create('Ext.button.Button',{
    id: 'buttonId',
    text: 'Recreate Tab',
    renderTo: Ext.getBody(),
    handler: function(){
        var tickets = tabs.child('#tickets');
        tickets.tab.show();

    }
});

  });

</script>
 </head>
  <body>
  <div id="tabs1">
     <div id="script" class="x-hide-display"></div>
     <div id="markup" class="x-hide-display"></div>
 </div>
</body>
</html>

但是它给出了Uncaught TypeError:单击按钮时无法读取null的属性"tab".为什么?

But it gives Uncaught TypeError: Cannot read property 'tab' of null on click of button. Why ?

推荐答案

关闭后,票证"选项卡将从选项卡面板中删除.因此,当您使用tabs.child('#tickets')查找它时,您会得到空值.在下一行中,您实际上是在调用null.tab,因此是该错误.您需要先关闭面板,然后再使用tabs.add将该面板放回原处.

After the close, the tickets tab is removed from the tab panel. Thus when you look for it using tabs.child('#tickets') you get null back. On the next line you are effectively calling null.tab hence the error. You'll need to keep track of the panel before it closes and then use tabs.add to bring it back.

这篇关于autoDestroy的行为:Extjs4中为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆