asdtiang的博客 感謝blogjava提供的博客交流平臺(tái)
          不多說,可以實(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'
              }

          }

          頁面主要代碼:
          <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)該很簡單的,看下就懂了。
          最后應(yīng)該注意下:導(dǎo)入AJAX腳本,因?yàn)閞emoteFunction用到了AJAX
          <g:javascript library="prototype" />


          天蒼蒼,野茫茫,風(fēng)吹草底見牛羊

          Feedback

          # re: grails 實(shí)現(xiàn)級(jí)聯(lián)下拉列表  回復(fù)  更多評(píng)論   

          2013-04-18 16:03 by 陳小龍
          it.area 能獲得值嗎 好像獲得不了

          posts - 80, comments - 24, trackbacks - 0, articles - 32

          Copyright © asdtiang

          asdtiang的博客 PaidMailz
          點(diǎn)擊廣告網(wǎng)賺A(每天4個(gè)廣告,每個(gè)0.0025美元,一個(gè)搜索廣告0.03美元)
          主站蜘蛛池模板: 乌苏市| 海淀区| 大名县| 长宁区| 宁蒗| 滨州市| 竹溪县| 曲阳县| 象山县| 高陵县| 淅川县| 北海市| 中西区| 富阳市| 兴宁市| 巩义市| 梅河口市| 东阳市| 缙云县| 荃湾区| 大竹县| 宜春市| 威海市| 胶南市| 偏关县| 屏山县| 大石桥市| 怀安县| 武隆县| 阳城县| 察隅县| 青冈县| 湘潭市| 麻栗坡县| 阳高县| 武鸣县| 北碚区| 甘德县| 东至县| 无棣县| 灌阳县|