Is it possible to change table row colour if it contains a certain value in a gsp?

笑着哭i 提交于 2019-12-12 02:56:37

问题


I have a table in a gsp containing 10 deiiferent values :

<table class="table table-striped">
<tr>
    <th scope="row">Name:</th>
    <td>
        ${person.name}
    </td>
</tr>
<tr>
    <th scope="row">Address:</th>
    <td>
        ${person.address}
    </td>
</tr>............

I need to highlight (either change the background or text clour on some of the values if they are present in an array also available in the gsp.

Is this possible? For example using g:if? Like :

  <tr>
    <th scope="row">Name:</th>
    <td>
               <g:if ${array}.contains("${person.name}")>
        //change styling of this cell
                   ${person.name}
                </g:if>
    </td>
</tr>

回答1:


This should work, but I've not tried it:

<td class="${array.contains( person.name ) ? 'highlight' : ''}">

So if it contains the name, then a 'highlight' class will be added to the td



来源:https://stackoverflow.com/questions/16567114/is-it-possible-to-change-table-row-colour-if-it-contains-a-certain-value-in-a-gs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!