extjs動態新增或刪除控制元件
阿新 • • 發佈:2019-01-03
背景:extjs 3.4
需求:新增或刪除textarea
程式碼:
var i =0;
this.addButton= new Ext.Panel({
layout:'hbox',
border:false,
scope:this,
items:[{
xtype:'button',
text:'增加',
handler:function(){
varpanel = Ext.getCmp("parentPanel");
vartextarea = new Ext.form.TextArea({
id:'textarea_'+i,
width:800
});
vardelBtn = new Ext.Button({
text:'刪除',
id:'del_'+i,
handler:function(btn){
var num = btn.id.substr(4); //獲取序號
varpn = Ext.getCmp("txPanel_"+num);
panel.remove(pn);
panel.doLayout();
}
});
vartxPanel = new Ext.Panel({
layout:'column',
id:'txPanel_'+i,
border:false,
width:1000,
defaults:{
columns:2
}
items:[textarea,delBtn]
});
panel.add(textarea);
panel.doLayout();
i++;
}
}]
});