EXT JS关闭弹出窗口

时间:2013-08-05 05:05:19

标签: extjs extjs4 extjs4.1

我有一个没有关闭按钮的弹出窗口,所以我必须刷新页面才能关闭弹出窗口。在这种情况下,我想在弹出窗口中添加一个按钮来关闭。

这是js代码:

function oseGetWIn(id, title, width, height)
{
    var win = Ext.create('Ext.window.Window', {
        id: id,
        name: id,
        title: title,
        width: width,
        height: height,
        closeAction:'destroy',
        autoScroll:'true',

    }); 
    return win; 
}

我尝试添加以下内容,但没有效果。

bbar: [
        {
          text: 'Close',
          handler: function () { this.up('.window').close(); }
         }
      ],

6 个答案:

答案 0 :(得分:1)

选择器不正确,它应该是window,它将找到具有匹配xtype的父级。

答案 1 :(得分:1)

这应该有效:

var win = Ext.create('Ext.window.Window', {
            title: 'test',
            width: 400,
            height: 200,
            bbar:[{
                text:'Close',
                handler: function(){
                    win.destroy();
                }
            }]
        })

工作示例:http://jsfiddle.net/RdVyz/

答案 2 :(得分:1)

嗯...还是没有回答? 解决方案很简单

var win = Ext.create('Ext.window.Window', {
        id: id,
        name: id,
        title: title,
        width: width,
        height: height,
        closeAction:'destroy',
        autoScroll:'true',
        closable:true,
        bbar:[{
            text:'Close',
            handler:function(bt){
                bt.up('window').close();
            }
        }]
    })

答案 3 :(得分:0)

试试这个

var win = Ext.create('Ext.window.Window', {
    id: id,
    name: id,
    title: title,
    width: width,
    height: height,
    closeAction:'destroy',
    autoScroll:'true',
    closable:true // add this attribute and you will get a close button on right top
});

编辑: 现在试试这个:

var win = Ext.create('Ext.window.Window', {
            id: id,
            name: id,
            title: title,
            width: width,
            height: height,
            closeAction:'destroy',
            autoScroll:'true',
            closable:true,
            bbar:[{
                text:'Close',
                handler:function(){
                    this.up('window').destroy();
                }
            }]
        })

答案 4 :(得分:0)

在我看来这是最简单的方法

var wind = Ext.WindowManager.getActive();

if(wind){
     wind.close();
}

答案 5 :(得分:-1)

试试这个 在关闭处理程序

this.up()向上()close()方法。; 要么 this.up()关闭();