在rails上的ruby中,我試圖更新2個partials。渲染部分有事件的帖子響應不起作用
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();
我的渲染產品非常好的。但是,當我對渲染的項目有適當的響應時,它只是不再發送ajax。所以我選擇的項目上的事件已經消失了,而我確定我已經用「selectionchanges();」重置了它們。在我的show.js.erb文件的末尾?
任何人都可以看到這個解決方案嗎?
問候和感謝提前
代碼塊表現得很奇怪:感謝@ jdl幫助我! – ReBa
不客氣。我希望你能爲你的問題找到一個好的答案。 – jdl
你有'selectionchanges'和'selectionChanges',是一個錯字? – RadBrad