在下面的代碼中,我手動檢查每個視圖是否有一些內容或它是否爲空。如果它有一些內容,那麼我正在摧毀它。我不想手動檢查每個視圖,我想要一個能夠動態選擇非空視圖的代碼,以便我可以銷燬該視圖並且不需要手動檢查。並且每次只有一個非空視圖。動態銷燬視圖
function reset_container() {
if (aasview != null) {
aasview.destroy();
}
if (alewives != null) {
alewives.destroy();
}
if (aa_amendview != null) {
aa_amendview.destroy();
}
if (aa_dispatchview != null) {
aa_view.destroy();
}
if (aa_postview != null) {
aa_postview.destroy();
}
if (cc_dispatchview != null) {
cc_dispatchview.destroy();
}
if (cc_postview != null) {
cc_postview.destroy();
}
if (cm_salesview != null) {
cm_salesview.destroy();
}
if(cc_view!=null){
cc_view.destroy();
}
if (cc_amendview != null) {
cc_amendview.destroy();
}
if (quotationview != null) {
quotationview.destroy();
}
if(truckview!=null){
truckview.destroy();
}
if (create_mnview != null) {
create_mnview.destroy();
}
if (create_stoview != null) {
create_stoview.destroy();
}
if(vehicle_view != null){
vehicle_view.destroy();
}
}
他們不是在數組中。每個視圖的創建方式不同。因爲我在選擇特定菜單(標題)項目時將這些不同的視圖放在同一個容器上。 – Ash
使用數組來存儲你的視圖,然後如我所示,Jasper_07在下面給出了很好的impl。 –