EL 表达式中的 OR 条件如何发挥作用?

发布于 2024-12-14 22:34:05 字数 573 浏览 2 评论 0原文

我想在此菜单中创建一个 OR 条件:

<li class="#{facesContext.viewRoot.viewId == ('/company/team.xhtml' or '/company/partnerships.xhtml' ) ? 'active' : '' }"><a class="item" href="company/company.xhtml">Company</a>
    <ul>
        <li><a href="company/team.xhtml">Team</a></li>
        <li><a href="company/partnerships.xhtml">Partnerships</a></li>
    </ul>
</li>

如果用户选择了 team.xthml 或partnerships.xhtml 页面,则将设置“active”值它位于

  • 标记中。
  • I would like to make an OR condition in this menu :

    <li class="#{facesContext.viewRoot.viewId == ('/company/team.xhtml' or '/company/partnerships.xhtml' ) ? 'active' : '' }"><a class="item" href="company/company.xhtml">Company</a>
        <ul>
            <li><a href="company/team.xhtml">Team</a></li>
            <li><a href="company/partnerships.xhtml">Partnerships</a></li>
        </ul>
    </li>
    

    That if the team.xthml or partnerships.xhtml page are selected by the user the 'active' value would be set it in the <li> tag.

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(1

    动听の歌 2024-12-21 22:34:05

    这是正确的语法:

    <li class="#{facesContext.viewRoot.viewId == '/company/team.xhtml' or facesContext.viewRoot.viewId == '/company/partnerships.xhtml' ? 'active' : '' }">
    

    要使其更短,您可以使用 #{view} 而不是 #{facesContext.viewRoot}

    <li class="#{view.viewId == '/company/team.xhtml' or view.viewId == '/company/partnerships.xhtml' ? 'active' : '' }">
    

    要使其更短,您可以将 #{view.viewId} 别名为

    <c:set var="viewId" value="#{view.viewId}" scope="request" />
    ...
    <li class="#{viewId == '/company/team.xhtml' or viewId == '/company/partnerships.xhtml' ? 'active' : '' }">
    

    This is the proper syntax:

    <li class="#{facesContext.viewRoot.viewId == '/company/team.xhtml' or facesContext.viewRoot.viewId == '/company/partnerships.xhtml' ? 'active' : '' }">
    

    To make it a bit shorter, you could use #{view} instead of #{facesContext.viewRoot}:

    <li class="#{view.viewId == '/company/team.xhtml' or view.viewId == '/company/partnerships.xhtml' ? 'active' : '' }">
    

    To make it yet shorter, you could alias the #{view.viewId} with <c:set>:

    <c:set var="viewId" value="#{view.viewId}" scope="request" />
    ...
    <li class="#{viewId == '/company/team.xhtml' or viewId == '/company/partnerships.xhtml' ? 'active' : '' }">
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文