使用Ajax部分修复渲染 [英] fix the render with ajax in partial

查看:114
本文介绍了使用Ajax部分修复渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试渲染另一个部分,就像这样:

I am trying to render in another partial, like this:

<% cobran = @detalleco.cobran %>
$("#cobran_<%= @detalleco.IdCobranza %>").fadeOut(500, function(){
  $(this).remove();
  $(".child").remove();
  $("#container_cobranza").html("<%=escape_javascript(render(:partial => 'cobranza/cobran', cobranza: cobran))%>");
});

但我收到此错误:

ActionView :: Template :: Error(未定义的局部变量或方法cobran' for #<#<Class:0xb47692ec>:0x83cb1500> Did you mean? cobran_url): 1: <tr id="cobran_<%= cobran.id %>"> 2: <td><%=cobran.id%> 3: 4: app/views/cobranza/_cobran.html.erb:1:in _app_views_cobranza__cobran_html_erb__36360536__1042659538' app/views/detallecob/create.js.erb:12:in _app_views_detallecob_create_js_erb__76211164__1041949938'

ActionView::Template::Error (undefined local variable or method cobran' for #<#<Class:0xb47692ec>:0x83cb1500> Did you mean? cobran_url): 1: <tr id="cobran_<%= cobran.id %>"> 2: <td><%=cobran.id%> 3: 4: app/views/cobranza/_cobran.html.erb:1:in_app_views_cobranza__cobran_html_erb__36360536__1042659538' app/views/detallecob/create.js.erb:12:in `_app_views_detallecob_create_js_erb__76211164__1041949938'

无法识别变量"cobran",因为视图中的渲染方式是这样的:

don't recognize the variable "cobran" because in the view is doing the render this way:

<tbody id="container_cobranza">
      <%= render @cobranza %>
</tbody>

在部分中放入"cobranza"的单数,即"cobran",如下所示:

And in the partial puts the singular of "cobranza" that is "cobran" like this:

<tr id="cobran_<%= cobran.id %>">
  <td><%=cobran.id%>


  <td><%=cobran.FechaReg%></td>
  <td><%=cobran.FechaVence%></td>
  <td><%=cobran.TipoDoc%></td>

</tr>

如何解决此问题?谢谢

推荐答案

您不能在javascript中使用该erb变量.通过data属性将其传递给javascript.添加到您的元素之一:data-cobran="<%= @detalleco.cobran %>"在元素上放置一个ID,然后通过ID var cobran = $("#nameOfId").data('cobran')

You can't use that erb variable in javascript. Pass it to the javascript via a data attribute. Add to one of your elements: data-cobran="<%= @detalleco.cobran %>" Put an id on the element and then access it by the id var cobran = $("#nameOfId").data('cobran')

之后,您可以使用它.

这篇关于使用Ajax部分修复渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆