首页 新闻 搜索 专区 学院

if-else 代码优化

0
悬赏园豆:10 [已解决问题] 解决于 2019-03-07 17:14

请问怎么优化下面的代码,在线等
if(appCode==null)
{
if(param.entityName=="User"||param.entityName=="AcUser")
{
dlg = this.modalCtrl.create(ViewSelectUserPage, param);
dlg.present();
}
else
{
dlg = this.modalCtrl.create(ViewSelectPage, param);
dlg.present();
}
}
else
{
if(param.entityName==appCode+".User"||param.entityName==appCode+".AcUser")
{
dlg = this.modalCtrl.create(ViewSelectUserPage, param);
dlg.present();
}
else
{
dlg = this.modalCtrl.create(ViewSelectPage, param);
dlg.present();
}
}
return new Promise<any[]>(resolve => {
dlg.onDidDismiss((result) => {
if (result) {
resolve(result);
}
})
});

alger_li的主页 alger_li | 初学一级 | 园豆:40
提问于:2019-03-07 16:21
< >
分享
最佳答案
0

appCode == null ? '' : appCode;
if (param.entityName == appCode + ".User" || param.entityName == appCode + ".AcUser") {
dlg = this.modalCtrl.create(ViewSelectUserPage, param);
dlg.present();
}else {
dlg = this.modalCtrl.create(ViewSelectPage, param);
dlg.present();
}
是不是可以这样

收获园豆:10
地火水 | 小虾三级 |园豆:1290 | 2019-03-07 16:37
其他回答(2)
0

public void test() {
dlg = initUserPage(appCode);
dlg.present();
return new Promise<any[]>(resolve = > {
dlg.onDidDismiss((result) = > {
if (result) {
resolve(result);
}
})
});
}

private Object initUserPage(String appCode){

    if (param.entityName == "User" || param.entityName == "AcUser") {
        return this.modalCtrl.create(ViewSelectUserPage, param);
    }

    if (param.entityName == appCode + ".User" || param.entityName == appCode + ".AcUser") {
        return this.modalCtrl.create(ViewSelectUserPage, param);
    }

    return this.modalCtrl.create(ViewSelectPage, param);

}
jerry-Tom | 园豆:4077 (老鸟四级) | 2019-03-07 16:37
0

appCode = appCode == null ? "" : appCode + ".";
if (param.entityName == "User" || param.entityName == "AcUser" || param.entityName == appCode + "User" || param.entityName == appCode + "AcUser")
{
dlg = this.modalCtrl.create(ViewSelectUserPage, param);
dlg.present();
}
else
{
dlg = this.modalCtrl.create(ViewSelectPage, param);
dlg.present();
}
return new Promise<any[]>(resolve =>
{
dlg.onDidDismiss((result) =>
{
if (result) { resolve(result); }
});
});

三人乐乐 | 园豆:3250 (老鸟四级) | 2019-03-07 16:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册