asdtiang的博客 感謝blogjava提供的博客交流平臺

          grails 實現(xiàn)級聯(lián)下拉列表

          Posted on 2010-08-10 11:22 asdtiang 閱讀(1665) 評論(1)  編輯  收藏 所屬分類: grails study
          不多說,可以實現(xiàn)多級,http://xihuyu2000.javaeye.com/blog/349722,這個地方可以實現(xiàn)兩級,但我這里可以實現(xiàn)多級,直接上代碼吧。

          說明,手機(jī)充值有服務(wù)商,面值,和區(qū)域,現(xiàn)在數(shù)據(jù)庫設(shè)計有點問題,不過能說明問題就行。

          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'])}"這個地方,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腳本,因為remoteFunction用到了AJAX
          <g:javascript library="prototype" />


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

          Feedback

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

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

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

          Copyright © asdtiang

          asdtiang的博客 PaidMailz
          點擊廣告網(wǎng)賺A(每天4個廣告,每個0.0025美元,一個搜索廣告0.03美元)
          主站蜘蛛池模板: 万全县| 涪陵区| 乌鲁木齐县| 广饶县| 张掖市| 三原县| 宁德市| 德钦县| 河曲县| 万载县| 油尖旺区| 桂林市| 营口市| 丰城市| 平度市| 沙洋县| 阿荣旗| 金华市| 泗水县| 廊坊市| 临洮县| 麟游县| 霍城县| 民勤县| 湖南省| 江西省| 朔州市| 辰溪县| 宁国市| 石河子市| 新野县| 江源县| 河源市| 南平市| 泸州市| 台中县| 石台县| 温州市| 南汇区| 盘山县| 永吉县|