我是JavaScript新手。我正在使用alert选项来显示地图图层。如果警报选项为true,则必须显示4个图层。否则它必须显示2层。使用普通图层访问
试图编写优化的代码。 现在我显示的图层为if(true){1,2,3,4} else{3,4}
。试图将优化代码{3,4}
写为常用层。
if true{1,2, + common layers} else{display common layers}
。有人
建议我的代码示例。
我是JavaScript新手。我正在使用alert选项来显示地图图层。如果警报选项为true,则必须显示4个图层。否则它必须显示2层。使用普通图层访问
试图编写优化的代码。 现在我显示的图层为if(true){1,2,3,4} else{3,4}
。试图将优化代码{3,4}
写为常用层。
if true{1,2, + common layers} else{display common layers}
。有人
建议我的代码示例。
你可以试试这个,
if(true){
// Layer1, Layer2.
}
// Layer3,Layer4.
switch(icheck){
case true :{1,2}; // no break statement used here
case false: {3,4};
break;
default : //your Operation whatever you want to perform on this.
break;
}
如果你的case语句true
然后它会执行你的{1,2}
,从错误的情况下{3,4}
,因为不使用中断。
如果您的案例陈述是false
那么它将执行您的{3,4}
只。之后,它会断开并离开开关。
我认为这是一个更好的方法,你应该实现。
谢谢