提问人:svennnx3 提问时间:3/18/2019 最后编辑:Magnus Melwinsvennnx3 更新时间:3/21/2019 访问量:755
如何在oncomplete中检查两个以上的条件
How can I check more than two conditions inside oncomplete
问:
我有 4 个条件要检查,我想在 oncomplete 语句中检查它。 我意识到我只能使用其他方法检查两个。 如果我使用 if -> else if -> else if -> else if 来检查 oncomplete 中的 4 个条件。 当我这样做时,它只能检查 if 和 else if(同样只有 2 个条件) 有什么方法可以检查两个以上的条件吗? 这是我的代码。该代码只能检查 if 和 1st else if
<a4j:commandLink .....
action ....
oncomplete=" if (1st condtition ) ; else if (2nd condition) ; else if (3th condition ) ; else if (4th condition)"
有什么想法吗?
答:
0赞
kealaxshan
3/18/2019
#1
如果你想检查true
if(1st condition && 2nd condition && 3rd condition && 4th condition){}
或任何一个true
if(1st condition || 2nd condition || 3rd condition || 4th condition){}
评论
1赞
svennnx3
3/18/2019
我想检查条件,因为每个条件都有与之相关的语句。例如,用户正在选择国家/地区,我的网站应该为我获得大陆。
0赞
kealaxshan
3/18/2019
您可以使用 switch 语句
0赞
svennnx3
3/18/2019
如何在 OnComplete 中使用 switch 语句?
0赞
svennnx3
3/18/2019
我不知道如何将其实现到我的 oncomplete 中。因为每个 if 都有与之相关的操作 - 取决于我的 if 条件的结果,例如: oncomplete=“if (condtion == true) dosomething, else if (condtiton2=true) dosomethingelse
0赞
kealaxshan
3/18/2019
switch (condtion == true) { case "india": // Blah break; case "usa": // Blah break; }
0赞
svennnx3
3/21/2019
#2
我为我自己的问题找到了一个 answear。我会在宣誓中解释这一点。但我会更恰当地为你和所有随时阅读它的人解释我的问题。所以:我有一个 .xhtml 文件,我在其中使用 Seam 框架和 JSF 来连接项目的前端和后端。我也在使用 AJAX。我有包含在正文中的:onclick,action,oncomplete,rendered。所以在 oncomplete 中我想检查 4 个不同的条件,取决于结果,我想从某个 java 类中调用一个方法。但 oncomplete 仅在其他情况下才支持。– svennnx3 3 分钟前 编辑
我想使用 if else if , else if , else if.它不会无休止地工作。所以我只做了 2 个条件(如果和 else)。我的方法只设置了 2 个布尔变量。然后,当我的布尔值为真时,我调用以显示一个对话窗口。这解决了我的问题,一次显示两个对话框,或者当只有一个变量为真时仅显示 1 个对话框:)
评论
&&
(x == x && y == y)
switch