一、通过Ext.window.Window直接创建并显示
Ext.create('Ext.window.Window', {
title:"my first window",
height:300,
width:500,
constrain:true,
modal:true,
icon:"../../js/extjs/icons/used/browser_window.png",
x:300,
y:200,
autoScroll:true,
html:'<div style="width:200px;height:200px">div content</div><div style="width:200px;height:200px">div content</div>',
renderTo:Ext.getBody()
}).show();
二、通过点击事件创建
var btn = Ext.get("btn");
btn.on("click", function() {
if(!Ext.getCmp("mywin")){
Ext.create("Ext.window.Window", {
id:"mywin",
title:"属性",
width:400,
height:300,
renderTo:Ext.getBody()
}).show();
}
});
三、先创建后控制其显示
var win = Ext.create("Ext.window.Window",{
id:"mywind",
title:"属性",
width:400,
height:300,
closeAction:'hide'
});
Ext.get("btn").on("click", function() {
win.show();
});
四、通过WinGroup管理多个窗口
var winGroup = new Ext.WindowGroup();
for(var index=0; index<5; index++){
var win = Ext.create('Ext.Window',{
title:'第'+index+'个窗体',
id:'win_'+index,
width:500,
height:400,
renderTo:Ext.getBody()
});
win.show();
winGroup.register(win);
}
var btnHide = Ext.create("Ext.button.Button",{
text:'全部隐藏',
renderTo:Ext.getBody(),
handler:function(){
winGroup.hideAll();
}
});
var btnShow = Ext.create("Ext.button.Button",{
text:'全部显示',
renderTo:Ext.getBody(),
handler:function(){
winGroup.each(function(cmp){
cmp.show();
});
}
});
var btnShowIndex = Ext.create("Ext.button.Button",{
text:'把第3个窗口显示在最前端',
renderTo:Ext.getBody(),
handler:function(){
winGroup.bringToFront('win_3');
}
});
五、在组件中添加子组件
var win = new Ext.window.Window({
title:"添加子组件",
width:'40%',
height:400,
renderTo:Ext.getBody(),
draggable:false,
resizable:false,
closable:false,
bodyStyle:"background:#ffc;padding:10px",
html:"this is content",
items: [
{ xtype:'button',
text:'确定',
handler:function(btn){
alert(btn.text);
}
},
{
xtype:'panel',
width:'100%',
height:200,
html:'<a href="#">我是面板</a>'
}]
});
win.show();
var win = new Ext.Window({
id:'mywin',
title:'我的窗口标题',
width:500,
height:300,
renderTo:Ext.getBody(),
bbar:[
{
text:'按钮1',
handler:function(btn){
console.log(btn.up('tbar'));
alert(btn.up('window').title);
}
},{
text:'按钮2',
handler:function(btn){
alert(Ext.getCmp('mywin').width);
}
},{
text:'按钮3',
handler:function(btn){
console.log(btn.ownerCt);
console.log(btn.ownerCt.ownerCt);
alert(btn.ownerCt.ownerCt.title);
}
}
]
});
win.show();