2012-12-19 6 views
6

레일에있는 루비에서 2 개의 부분을 업데이트하려고합니다.이벤트가있는 부분 렌더링의 응답이 작동하지 않습니다.

show.html.erb :

<div id="filters"><%= render :partial => "pricelistfilters" %></div> 

pricelistfilters.html.erb :

<% @properties.each do |prop| %> 
    #Render the page on properties (and the newproperties) 
    #<select ...><option>...</option><option>...</option> 
    #</select> 
<% end %> 

products.js - 렌더링 부분

용> 이벤트
$(window).ready(function(){ 
    selectionchanges(); 
}); 
function selectionchanges(){ 
    $('#filters select').change(function(){ 
    //Doing stuff to send with ajax 

    //Ajax: 
    $.ajax({ 
     url: document.URL, 
     type: 'POST', 
     data: params 
    }); 
    }); 
} 

products_controller.rb - 변경 내용을 처리 할 수> 코드는

def show 
    #Changing the properties (and the pricelist properties) 
    @properties #is filled 
    @newproperties #is filled 
    respond_to do |format| 
    format.html 
    format.js 
    end 
end 

show.js.erb했다

$('#filters').html('<%= escape_javascript(render :partial => "pricelistfilters") %>'); 
selectionChanges(); 

내 렌더링 항목이 완벽하게 좋은 것입니다. 그러나 렌더링 된 항목에 대해 적절한 응답을 얻었을 때 더 이상 아약스를 보내지 않습니다. 그래서 내가 선택한 아이템에 대한 이벤트는 사라졌지 만, "selectionchanges();로 리셋했습니다. 내 show.js.erb 파일 끝나고?

누구든지 해결책을 찾을 수 있습니까? 사전에

인사와 감사

+0

코드 블록이 이상하게 작동하고있었습니다. [email protected]로 나를 도와주세요! – ReBa

+0

반갑습니다. 나는 당신이 당신의 문제에 대해 좋은 대답을 찾길 바랍니다. – jdl

+3

'selectionchanges'AND 'selectionChanges', 오타입니다? – RadBrad

답변

2

울부 짖는 소리로, product.js에 jQuery의 라이브 기능을 사용해보십시오 : 기본적으로

$(window).ready(function(){ 
    selectionchanges(); 
}); 
function selectionchanges(){ 
    $('#filters select').live('change', function(){ 
    //Doing stuff to send with ajax 

    //Ajax: 
    $.ajax({ 
     url: document.URL, 
     type: 'POST', 
     data: params 
    }); 
    }); 
} 

, 당신은 당신이 먼저 바운드 HTML 돔의 요소를 교체하고 이벤트 '변경'을 (를) 클릭하십시오. jQuery는 요소를 대체하여도 라이브 바인딩을 사용하여 바인딩을 다시 수행합니다.

희망이 있습니다.

+0

이 사진을 보셔야합니다. 완벽하게 작동합니다! 고마워. – ReBa

관련 문제