RJS 错误“对象不支持此属性”元素更新时

发布于 2024-12-11 06:18:37 字数 2133 浏览 0 评论 0原文

我在控制器中有以下代码。 我正在根据另一个下拉框中的选择动态填充一个下拉框。

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;
})

在更改下拉框中的选择时,我收到一个错误元素不支持此属性的弹出窗口。请在此处帮助我。

I have the following code in the controller.
I am populating a drop down box dynamically based on the selection from another drop down box.

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 

view code:

-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"

partials code :
= select_tag "releases",options_from_collection_for_select(releases,"id","name",params[:releases])

Jquery:
//change the releases drop down based on the selction of the projects drop down.

$('.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;
})

I am getting an error element doesn't support this property" as a pop up on chaning the selection in the drop down box. Please help me out here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2024-12-18 06:18:37

作为简单的解决方法,尝试在控制器中使用此代码:

respond_to do |format| 
  format.js render :partial => 'releases', :locals { :releases => releases }
end

在releases.js.haml中:

   $('#releases').html('#{render :partial => '<some_old_html_partial>', :locals => {:releases => releases}}')

As simple workaround try to use this code in controller:

respond_to do |format| 
  format.js render :partial => 'releases', :locals { :releases => releases }
end

In releases.js.haml:

   $('#releases').html('#{render :partial => '<some_old_html_partial>', :locals => {:releases => releases}}')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文