不多說,可以實現多級,http://xihuyu2000.javaeye.com/blog/349722,這個地方可以實現兩級,但我這里可以實現多級,直接上代碼吧。
說明,手機充值有服務商,面值,和區域,現在數據庫設計有點問題,不過能說明問題就行。
class TelDeltaPro {
String id
String name//服務商
String area//區域
String price//面值
String goodId
int sum//沖值總次數
static mapping={
id generator:'uuid'
}
}
頁面主要代碼:
主要是onchange="${remoteFunction(controller:'telDeltaPro', action:'price', params:'\'name=\'+this.value', update:[success:'price'])}"這個地方,remoteFunction查下文檔就可以了。
contorller主要代碼如下:
最后應該注意下:導入AJAX腳本,因為remoteFunction用到了AJAX
天蒼蒼,野茫茫,風吹草底見牛羊
說明,手機充值有服務商,面值,和區域,現在數據庫設計有點問題,不過能說明問題就行。












<tr>
<td><span class="indexText2">服務商</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">地區</span></td>
<td>
<div id="area"></div>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交"></td>
</tr>
<td><span class="indexText2">服務商</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">地區</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'])}"這個地方,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")
}
代碼應該很簡單的,看下就懂了。 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")
}
最后應該注意下:導入AJAX腳本,因為remoteFunction用到了AJAX
<g:javascript library="prototype" />
天蒼蒼,野茫茫,風吹草底見牛羊