我有一个像表格行一样的组件,称为 flightLegComponent ,如下所示:
[ flight leg component ] [-] [+]
[ flight leg component] [-] [+]
...
当按下 [-] 按钮时,该组件将被从父面板中删除。
我在 [-] 按钮上添加了一个监听器,在监听器中,我调用
this.remove(theFlightLegComponent);
其中' this '是父组件。
这会引发异常,显然,您不能删除事件处理程序中的组件......删除它的正确方法是什么?延迟后调用方法?
新的:
面板的结构如下:
_flightLegRow: function(removable) {
var flightLegInput = new xx.yy.zz.search.FlightLegInput({
columnWidth: .8
});
var legId = 'flightLeg-' + this.legs++;
var c = {
border: 0,
width: '90%',
layout: 'column',
id: legId,
items: [
flightLegInput,
{
columnWidth: .2,
margin: 10,
border: 0,
layout: {
type: 'column'
},
items: [{
xtype: 'button',
text: '-',
disabled: !removable,
listeners: {
click: Ext.Function.bind(function() {
//debugger;
this.remove(legId, true);
}, this)
}
},{
xtype: 'button',
text: '+',
listeners: {
click: Ext.Function.bind(function(){
this.add(this._flightLegRow(true));
}, this)
}
}]
}
]
};
return c;
}