1

我有一个小问题,不知道+白发。

我不太了解 gsp、groovy、grails 等。但情况如下:

例如,如果我从 mongodb 获得的数字大于 4.5,我需要显示图像。

我尝试了许多不同的东西:

                    <g:if test="${profil.punkte >0.1}">
                    <img src="${resource(dir: 'images', file: '1_5.gif')}" alt="gesamtbewertung in sternen" >
                    </g:if>
                    <g:elseif test="${profil.punkte >1.49}">
                    <img src="${resource(dir: 'images', file: '2_5.gif')}" alt="gesamtbewertung in sternen" >
                    </g:elseif>
                    <g:elseif test="${profil.punkte >2.49}">
                    <img src="${resource(dir: 'images', file: '3_5.gif')}" alt="gesamtbewertung in sternen" >
                    </g:elseif>
                    <g:elseif test="${profil.punkte >3.49}">
                    <img src="${resource(dir: 'images', file: '4_5.gif')}" alt="gesamtbewertung in sternen" >
                    </g:elseif>
                    <g:elseif test="${profil.punkte >4.49}">
                    <img src="${resource(dir: 'images', file: '5_5.gif')}" alt="gesamtbewertung in sternen" >
                    </g:elseif>

我尝试了很多不同的语法来解决这个问题,但它不起作用。在上面的版本中,它总是显示 1_5.gif

“profil.groovy”中的条目看起来…… 像:

class Profil {
ObjectId id
...
...
double punkte
}

mongodb 的 JSON 中的条目如下所示:

 "punkte": 4.3,

我只需要输入 ${profil.punkte} 并得到 4.3 渲染。

即使我的英语不好,希望你能理解我的问题。我会在我的笔记本电脑上做一个后空翻来解决!

4

1 回答 1

2

好吧,你需要创造更好的条件。你看到 4.3 大于 0.1 了吗?然后它总是进入第一个 if 而不是别的。

在您的条件中添加一些限制,它将起作用。

于 2012-10-01T21:24:41.057 回答