【发布时间】:2011-12-10 16:04:16
【问题描述】:
我在控制器中有以下代码。 我正在根据另一个下拉框中的选择动态填充一个下拉框。
def update_releases
project = Project.find(params[:project_id])
releases = project.releases
puts "releases==#{releases}"
render :update do |page|
page.replace_html 'releases', :partial => 'releases', :object => releases
end
查看代码:
-form_tag reports_path(report_type=1),:method => :get, :multipart => true ,:id => "filter" do
%table.grid.full
%tr
%td.grid.full_panels{:style => "width: 20%"}
Project:
%td.grid.full_panels{:style => "width: 20%"}
//= select_tag "projects",options_from_collection_for_select(projects,"id","name",params[:projects]),{:onchange => "#{remote_function(:url => {:action => "update_releases"},:with => "'project_id='+value")}"}
= select_tag "projects",options_from_collection_for_select(projects,"id","name",params[:projects]), :class => "update_releases"
%td.grid.full_panels{:style => "width: 20%"}
Releases:
%td.grid.full_panels{:style => "width: 20%"}
<div id="releases">
= render :partial => 'releases', :object => @releases
%td.grid.full_panels{:style => "width: 20%"}
Cycles:
%td.grid.full_panels{:style => "width: 20%"}
<div id="cycles">
= render :partial => 'cycles', :object => @cycles
%tr
%td.grid.full_panels{:style => "width: 20%"}
%td.grid.full_panels{:style => "width: 20%"}
%td.grid.full_panels{:style => "width: 20%"}
=submit_tag "Submit"
= javascript_include_tag "pages/ic"
部分代码: = select_tag "releases",options_from_collection_for_select(releases,"id","name",params[:releases])
jquery: //根据项目下拉列表的选择更改发布下拉列表。
$('.update_releases').live("change", function(){
$.ajaxSetup({beforeSend: function(xhr) {xhr.setRequestHeader("X-CSRF-Token", $("meta[name='csrf-token']").attr("content")); }});
var project_id=($(this).val());
$.post('/reports/update_releases', {project_id: project_id});
return false;
})
我收到一个错误元素不支持此属性”作为更改下拉框中选择的弹出窗口。请在此处帮助我。
【问题讨论】:
-
1.
cycles是在哪里定义的? 2.添加一些查看代码以查看全图.. -
嗨,马克我已经添加了完整的代码。另外请让我知道是否要在 jquery 中进行一些更改以包括 page.replace_html。
-
使用
#releases而不是<div id="releases">。 : 看起来您的 HAML 无效。检查客户端的 HTML 输出是否存在发布和循环 div。 -
存在版本和周期。 Replace_html 使用原型。谁能告诉我相应的jquery方法
-
replace_html是 RJS 方法。它将你的红宝石编译成 JS。如果您将原型设置为 RJS 后端,那么将使用原型方法,对于 jQuery 也是如此。至于html的替换:见方法html()on [api.jquery.com/html/](api.jquery.com/html)
标签: ruby-on-rails ajax jquery rjs