嗨我試圖使用兩個下拉組合框列出商店。如果你沒有選擇國家或城市列出所有商店。根據城市國家或兩者的其他方式列出。順便說一下,我沒有創建控制器,我使用generate-all生成了tehm。 這裏是我的看法;g:選擇在grails中使用兩個組合框
<g:form action="index" method="POST">
<div class="fieldcontain">
<g:select name="ddlCountry" noSelection="[null:message(code:'default.select.label',default:'Seçiniz...')]"
from="['UK', 'NL', 'DE']"
value="${params.ddlCountry}"/>
<g:select name="ddlCity"
from="['AMSTERDAM', 'Erfurt', 'Manchester','London']"
value="${params.ddlCity}"/>
<input class="btn btn-danger" type="submit" value="Listele" />
<g:each in="${shopList}" status="i" var="shopInstance">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td>
<g:link controller="shop" action="show" params="[id:shopInstance.id]">
${fieldValue(bean: shopInstance, field: "shopName")}
</g:link>
</td>
<td>${fieldValue(bean: shopInstance, field: "shopAdress1")}</td>
<td>${fieldValue(bean: shopInstance, field: "shopPostcode")}</td>
<td>${fieldValue(bean: shopInstance, field: "shopCity")}</td>
<td>${fieldValue(bean: shopInstance, field: "shopCountry")}</td>
<td>${fieldValue(bean: shopInstance, field: "shopDateEdited")}</td>
</tr>
</g:each>
</div>
</g:form>
,這裏是店控制器指數
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
if(params.ddlCountry || params.ddlCity) {
def shops = Shop.withCriteria {
if (params.ddlCountry) {
like('shopCountry', '%${params.ddlCountry}%')
}
if (params.ddlCity) {
like('shopCity', '%${params.ddlCity}%')
}
}
[shopList:shops]
}
else{
respond Shop.list(params), model:[shopCount: Shop.count()]
}
}
它的上市,每次所有的商店。當我點擊按鈕,頁面清爽,但沒有發生
我終於解決了我的問題。我在這裏寫信也許幫助了某人。 noSelection =「['':message(code:'default.select.label',default:'Seçiniz...')]」我刪除了空值並替換爲''。並在控制器頁面我刪除第一如果和其他博客。代碼工作得很好。 –