grails 實(shí)現(xiàn)級(jí)聯(lián)下拉列表
Posted on 2010-08-10 11:22 asdtiang 閱讀(1665) 評(píng)論(1) 編輯 收藏 所屬分類: grails study不多說,可以實(shí)現(xiàn)多級(jí),http://xihuyu2000.javaeye.com/blog/349722,這個(gè)地方可以實(shí)現(xiàn)兩級(jí),但我這里可以實(shí)現(xiàn)多級(jí),直接上代碼吧。
說明,手機(jī)充值有服務(wù)商,面值,和區(qū)域,現(xiàn)在數(shù)據(jù)庫設(shè)計(jì)有點(diǎn)問題,不過能說明問題就行。
class TelDeltaPro {
String id
String name//服務(wù)商
String area//區(qū)域
String price//面值
String goodId
int sum//沖值總次數(shù)
static mapping={
id generator:'uuid'
}
}
頁面主要代碼:
主要是onchange="${remoteFunction(controller:'telDeltaPro', action:'price', params:'\'name=\'+this.value', update:[success:'price'])}"這個(gè)地方,remoteFunction查下文檔就可以了。
contorller主要代碼如下:
最后應(yīng)該注意下:導(dǎo)入AJAX腳本,因?yàn)閞emoteFunction用到了AJAX
天蒼蒼,野茫茫,風(fēng)吹草底見牛羊
說明,手機(jī)充值有服務(wù)商,面值,和區(qū)域,現(xiàn)在數(shù)據(jù)庫設(shè)計(jì)有點(diǎn)問題,不過能說明問題就行。












<tr>
<td><span class="indexText2">服務(wù)商</span></td>
<td><g:select name="proName"
from="${com.likai.asdtiang.domain.platform.TelDeltaPro.list()}"
optionKey="name" optionValue="name"
onchange="${remoteFunction(controller:'telDeltaPro', action:'price', params:'\'name=\'+this.value', update:[success:'price'])}"></g:select>
</td>
</tr>
<tr>
<td><span class="indexText2">面值</span></td>
<td>
<div id="price"></div>
</td>
</tr>
<tr>
<td><span class="indexText2">地區(qū)</span></td>
<td>
<div id="area"></div>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交"></td>
</tr>
<td><span class="indexText2">服務(wù)商</span></td>
<td><g:select name="proName"
from="${com.likai.asdtiang.domain.platform.TelDeltaPro.list()}"
optionKey="name" optionValue="name"
onchange="${remoteFunction(controller:'telDeltaPro', action:'price', params:'\'name=\'+this.value', update:[success:'price'])}"></g:select>
</td>
</tr>
<tr>
<td><span class="indexText2">面值</span></td>
<td>
<div id="price"></div>
</td>
</tr>
<tr>
<td><span class="indexText2">地區(qū)</span></td>
<td>
<div id="area"></div>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交"></td>
</tr>
主要是onchange="${remoteFunction(controller:'telDeltaPro', action:'price', params:'\'name=\'+this.value', update:[success:'price'])}"這個(gè)地方,remoteFunction查下文檔就可以了。
contorller主要代碼如下:
def price={
log.info params.name+"name"
session.putValue "telName",params.name
def str="""<select id="proName" name="price" onchange="${remoteFunction(controller:'telDeltaPro',
action:'area', params:'\'price=\'+this.value', update:[success:'area'])}">"""
def li=TelDeltaPro.findAllByName(session.telName)
li.each{
str=str+"""<option value="${it.price}">${it.price}</option>"""
}
str=str+"""</select>"""
render(text:str,contentType:"text/html",encoding:"UTF-8")
}
def area={
log.info params.price+" price"
def str="""<select name="area" >"""
def li=TelDeltaPro.findAllWhere(name:session.telName, price:params.price)
li.each{
str=str+"""<option value="${it.area}">${it.area}</option>"""
}
str=str+"""</select>"""
render(text:str,contentType:"text/html",encoding:"UTF-8")
}
代碼應(yīng)該很簡單的,看下就懂了。 log.info params.name+"name"
session.putValue "telName",params.name
def str="""<select id="proName" name="price" onchange="${remoteFunction(controller:'telDeltaPro',
action:'area', params:'\'price=\'+this.value', update:[success:'area'])}">"""
def li=TelDeltaPro.findAllByName(session.telName)
li.each{
str=str+"""<option value="${it.price}">${it.price}</option>"""
}
str=str+"""</select>"""
render(text:str,contentType:"text/html",encoding:"UTF-8")
}
def area={
log.info params.price+" price"
def str="""<select name="area" >"""
def li=TelDeltaPro.findAllWhere(name:session.telName, price:params.price)
li.each{
str=str+"""<option value="${it.area}">${it.area}</option>"""
}
str=str+"""</select>"""
render(text:str,contentType:"text/html",encoding:"UTF-8")
}
最后應(yīng)該注意下:導(dǎo)入AJAX腳本,因?yàn)閞emoteFunction用到了AJAX
<g:javascript library="prototype" />
天蒼蒼,野茫茫,風(fēng)吹草底見牛羊