[求助] ExtJs问题,如何动态添加Window控件的items项

Matumoto 2009-05-08 09:54:40

var c_window = new Ext.Window({
title: 'title',
width: 950,
height: 530,
plain: true,
closeAction: 'hide',
defaults: {
anchor: '95%'
},
items:[user1],
modal: true,
buttons: [{
text: '关闭',
handler: function(){
c_window.hide();
}
}]
});

Window控件的items初始化有一个项user1
如果再添加一个项user2?

c_window.items.length=2;
c_window.items[1]=user2;//这样写不对
c_window.items.add(user2);//这样也不对
...全文
3633 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
豆虫 2011-07-28
  • 打赏
  • 举报
回复
win.add(user2);
win.doLayout();
qq12300119 2011-07-28
  • 打赏
  • 举报
回复
ding 我也想知道
liuzuowei007 2010-05-13
  • 打赏
  • 举报
回复
c_window.items.add(你要添加的组件);
c_window.doLayout();
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 h155290688 的回复:]
如果是3.0以上重新渲染好像是window.doLayout();

add( Object/Array component, Object (Optional), Object (Optional) ) : Ext.Component
Adds Component(s) to this Container. Description : <ul class="mdetail-params">……
[/Quote]

顶这个!能用。
hilinw126 2010-03-25
  • 打赏
  • 举报
回复
借2楼代码修改:

var user1 = new Ext.form.TextField({

});
var user2= new Ext.form.TextField({

});
var user2= new Ext.form.TextField({

});
...
var items = [];
if(条件1){
items.push(user1);
}else if(条件2){
items.push(user2);
items.push(user3);
}



var c_window = new Ext.Window({
title: 'title',
width: 950,
height: 530,
plain: true,
closeAction: 'hide',
defaults: {
anchor: '95%'
},
items:items,


萝asdf 2010-03-19
  • 打赏
  • 举报
回复
Ext.namespace("Ext.dojoChina.demo") ;

Ext.dojoChina.demo.NewsWindow = function(_record,obj){
var _me = this ;
Ext.dojoChina.demo.NewsWindow.superclass.constructor.call(this, {
title:_record.get("LOGID"),
width: 500,
height:300,
resizable:false,
layout: "fit",
plain:true,
bodyStyle:"padding:5px;",
buttonAlign:"right",
buttons: [{
text: "关 闭",
handler:function(){
_me.close() ;
}
}],
items:[obj]
});
}
Ext.extend(Ext.dojoChina.demo.NewsWindow , Ext.Window) ;
------------------------------------------------------------------
var alertlog=new Ext.FormPanel({});
var record=this.getSelectionModel().getSelected();
var logwin = new Ext.dojoChina.demo.NewsWindow(record,alertlog) ;
logwin.show() ; 你可以吧那个record参数去掉
hailang7210 2010-01-22
  • 打赏
  • 举报
回复
h155290688 2010-01-22
  • 打赏
  • 举报
回复
如果是3.0以上重新渲染好像是window.doLayout();

add( Object/Array component, Object (Optional), Object (Optional) ) : Ext.Component
Adds Component(s) to this Container. Description : <ul class="mdetail-params"> Fires the beforeadd event before addin...
Adds Component(s) to this Container.



Description :

Fires the beforeadd event before adding
The Container's default config values will be applied accordingly (see defaults for details).
Fires the add event after the component has been added.


Notes :

If the Container is already rendered when add is called, you may need to call doLayout to refresh the view which causes any unrendered child Components to be rendered. This is required so that you can add multiple child components if needed while only refreshing the layout once. For example:
var tb = new Ext.Toolbar();
tb.render(document.body); // toolbar is rendered
tb.add({text:'Button 1'}); // add multiple items (defaultType for Toolbar is 'button')
tb.add({text:'Button 2'});
tb.doLayout(); // refresh the layout
Warning: Containers directly managed by the BorderLayout layout manager may not be removed or added. See the Notes for BorderLayout for more details.
Parameters:
component : Object/Array
Either a single component or an Array of components to add. See items for additional information.

(Optional) : Object
component_2
(Optional) : Object
component_n
Returns:
Ext.Component
component The Component (or config object) that was added.
lxhxyy_2009 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 matumoto 的回复:]
JScript codevar c_window=new Ext.Window({
title:'title',
width:950,
height:530,
plain:true,
closeAction:'hide',
defaults: {
anchor:'95%'
},
items:[user1],
modal:true,
buttons: [{
text:'关闭',
handler:function(){
c_window.hide();
}
}]
});
Window控件的items初始化有一个项user1
如果再添加一个项user2?

c_window.items.length=2;
c_window.items[1]=user2;//这样写不对
c_window.items.add(user2);//这样也不对
[/Quote]
我用怎么就不对呢
lxhxyy_2009 2010-01-22
  • 打赏
  • 举报
回复
我按楼上说的试了,怎么还不对呢
s000rd 2010-01-22
  • 打赏
  • 举报
回复
顶下
Ghost_520 2009-05-08
  • 打赏
  • 举报
回复

<script type="text/javascript">
var user1 = new Ext.form.TextField({

})
var user2= new Ext.form.TextField({

})

var c_window = new Ext.Window({
title: 'title',
width: 950,
height: 530,
plain: true,
closeAction: 'hide',
defaults: {
anchor: '95%'
},
items:[user1],
modal: true,
buttons: [{
text: '关闭',
handler: function(){
c_window.hide();
}
},{
text: '添加',
handler: function(){
c_window.add(user2); // 添加新组件
c_window.render(); // 添加后需要重新渲染一遍。
}
}]
});

c_window.show();

</script>

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧