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美元)
          主站蜘蛛池模板: 鄂托克前旗| 虞城县| 佛山市| 五寨县| 安国市| 山阴县| 金堂县| 灯塔市| 秭归县| 鲁甸县| 旺苍县| 伊金霍洛旗| 建宁县| 周口市| 龙山县| 新干县| 桐乡市| 江西省| 扶风县| 都匀市| 鹤壁市| 长乐市| 青河县| 鹤庆县| 镇平县| 宁蒗| 阿图什市| 丹巴县| 伊川县| 礼泉县| 景德镇市| 敖汉旗| 尼木县| 彰武县| 广州市| 金阳县| 黄陵县| 安西县| 达拉特旗| 林口县| 西丰县|