2016-11-22 75 views
0

我想在另一部分呈現,像這樣的AJAX渲染:修復與部分

<% 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 ::模板錯誤(未定義的局部變量或方法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' 應用/視圖/ detallecob/create.js.erb:12:在`_app_views_detallecob_create_js_erb__76211164__1041949938'

不識別變量 「cobran」,因爲在該視圖在做渲染這樣:

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

而且在部分放奇「cobranza」,也就是「cobran」像這樣的:

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


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

</tr> 

我怎樣才能解決這個問題呢?謝謝

回答

1

你不能在JavaScript中使用該erb變量。通過數據屬性將它傳遞給javascript。添加到您的元素中的一個:data-cobran="<%= @detalleco.cobran %>"在元素上添加一個ID,然後通過ID訪問它var cobran = $("#nameOfId").data('cobran')

之後,您可以使用它。