gpt4 book ai didi

javascript - 动态销毁 View

转载 作者:行者123 更新时间:2023-11-30 12:48:02 25 4
gpt4 key购买 nike

在下面的代码中,我手动检查每个 View 是否有内容或为空。如果它有一些内容,那么我正在销毁它。我不想手动检查每个 View ,我想要一个动态选择非空 View 的代码,这样我就可以销毁该 View ,而无需手动检查。而且一次只有一个非空 View 。

    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();
}
}

最佳答案

您如何创建 View ?如果它们在一个聚合中(例如在 SplitApp 母版/详细信息页面或应用程序页面中)或者甚至只是在一个数组中,您可以简单地遍历它们以简化您的代码:

例如存储在数组中:

[view1, view2, view3].forEach(function(view) {
if (view != null) { //might not need this test depending on how you populate the array
view.destroy();
}
})

例如存储在 sap.m.SplitApp detailPages 聚合中:

this.oRoot.getDetailPages().forEach(function(view) {
view.destroy();
});

如果没有代码的上下文,很难提供任何具体细节。 ;-) 我不确定你为什么需要销毁它们?

关于javascript - 动态销毁 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21899322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com