# app\controllers\examples_controller.rb
ruby 代码
 
  1. class ExamplesController < ApplicationController  
  2.   
  3.   def ajax_select  
  4.     @items = %w{AA BB}  
  5.   end  
  6.     
  7.   def get_sub_items  
  8.     if params[:item] == "AA"  
  9.       @sub_items = %w{AA1 AA2}  
  10.     else  
  11.       @sub_items = %w{BB1 BB2}  
  12.     end  
  13.       
  14.     render :partial => "select"  
  15.   end  
  16. end  
# app\views\examples\ajax_select.rhtml
xml 代码
 
  1. <%= javascript_include_tag :defaults %>  
  2.   
  3. <h1>Examples#ajax_select</h1>  
  4. <p>Find me in app/views/examples/ajax_select.rhtml</p>  
  5.   
  6. <%= select :obj, :att,  @items, {}, :onchange => remote_function(:update => "sub_items",  
  7.        :method => "get",  
  8.        :with => "'item=' + value",  
  9.        :url => { :controller => :examples, :action => :get_sub_items})   
  10.        %>  
  11. <div id="sub_items">  
  12.   <select></select>  
  13. </div>  
#app\views\examples\_select.rhtml
ruby 代码
 
  1. <%= select(:obj:item@sub_items) %>  
评论
发表评论

您还没有登录,请登录后发表评论

open2ye
搜索本博客
我的相册
Ac44ad89-992f-34f7-973c-60b25a6ddc0c-thumb
action_auth
共 26 张
最近加入圈子
存档
最新评论