0

我有一个问题,我需要考虑 4 个布尔值的可能选项的每种组合。例如

我有 4 个布尔值,useFeatured、groupBy、orderBy 和升序。可能的组合是..

featured.
featured & orderby.
featured & orderby & groupby.
featured & orderby & groupby & ascending.

featured & groupby.
featured & groupby & ascending.

featured & ascending
featured & ascedning & orderby

orderby
orderby & groupby
orderby & groupby & ascending

groupby
groupby & ascending

ascending
ascending & orderby

目前,对于这些选项,我有一个巨大的 if else if else 树,我发现很难相信这是唯一的解决方案,但我想不出其他任何东西。

这是 if else 树的链接。

if(featured){
if(orderby){
    if(groupby){
            if(ascedning){
                    //featured orderby groupby ascending
            }else{
                    //featured orderby groupby
            }
    }else{
            //featured orderby
    }
}else if(groupby){
    if(ascedning){
            //featured groupby ascending
    }else{
            //featured groupby
    }
}else if(ascending){
    if(orderby){
            //featured ascending orderby
    }else{
            //featured ascending
    }
}else{
    //featured
}
 }else if(orderby){
    if(groupby){
            if(ascending){
                    //orderby groupby ascending
            }else{
                    //orderby groupby
            }
    }
}else if(groupby){
    if(ascending){
            //groupby ascending
    }else{
            //groupvy
    }
 }else if(ascending){
    if(orderby){
            //ascending & orderby
    }else{
            //ascending
    }
 }else{
    //orderby
 }

Pastebin 如果格式混乱。http://pastebin.com/ECgASU3C

有人有更好的解决方案我可以采用吗?请救救我!

4

1 回答 1

0

您可以为此使用开关盒...但如果是更好的选择

于 2013-04-10T09:24:37.207 回答