test.rhtml的代码:
<%= javascript_include_tag :defaults %>
<%= select(:city, :province_id, @provinces, {},
{"onchange" => remote_function(
:with => "'province_id='+value",
:update => 'city_select',
:url => { :action => :select_cities_with_ajax })})
%>
<div id='city_select'>
<%= select( :county, :city_id, @cities, options = {},
html_options = { "onchange" => remote_function(
:with => "'city_id='+value",
:update => 'county_select',
:url => { :action => :select_counties_with_ajax })})
%>
</div>
<div id='county_select'><%= select(:sth, :county_id, @counties) %></div>
_select_city.rhtml代码:
<%= select(:county, :city_id, @cities, {},
{"onchange" => remote_function(
:with => "'city_id='+value",
:update => 'county_select',
:url => { :action => :select_county_with_ajax } )} )
%>
_select_county.rhtml代码:
<%= select(:sth, :county_id, @sights) %>
controller代码:
def select_city_with_ajax
@cities = Province.find(params[:province_id]).cities.map{|u| [u.name,u.id]}
render :partial => "select_city"
end
def select_county_with_ajax
@counties = City.find(params[:city_id]).counties.map{|u| [u.name,u.id]}
render :partial => "select_county"
end
分享到:
相关推荐
android sqlite table多级联动 管理本地数据库
Recyclerview实现列表联动
echarts折线图+饼图双图联动示例
最新的省市区三表联动json文件,可直接转为MySQL语句。
顶部有表头,表头下方有多个可横向左右滑动的tableview,tableview与表头保持联动
城市省份联动表,条理还算清晰,拿来就能用,城市村镇的有,联动表
省市区三级联动表,单表结构。 34省、直辖市,369市,2848县与区级数据。 -- 省级查询 select * from area where LEVEL=1 -- 市级查询 select * from area where LEVEL=2 -- 区县级查询 select * from area where ...
消防系统中常见连锁触发和连锁控制信号以及联动触发信号、联动控制信号和联动反馈信号表.pdf
Echart3多图联动,一个时间轴控制多个图,希望能够帮到大家!
ASP二级、三级单表联动、ASP单表联动
基于Excel的切片器实现多透视表联动分析 在商业智能和数据分析领域,Excel是一个非常流行的工具,能够帮助用户快速生成报表和数据分析结果。然而,随着数据规模的增加和复杂度的提高,使用Excel进行数据分析变得...
mysql全国城市三级联动表,可以分为三张表,可以合成一张表,里面有一份合成一张表的备份,共享一下,希望对大家有所帮助
android 列表三级联动android 列表三级联动android 列表三级联动android 列表三级联动android 列表三级联动android 列表三级联动android 列表三级联动
不要资源分 就是 为大家提供方便 在网上找的 是一个数据表的三级联动 自己修改成了 三个表的三级联动
省市区的三级联动-数据表
消防联动调试记录表(通用).pdf
省市县三级联动和商品类型二级联动excel表
全球区域的四级联动表,将近7000条数据,从国家=》省份=》市=》县区
MySQL版省市区表 ---三级联动 省市区三表合一表 三千条数据