是否有可能改變params哈希表的值時,一個JavaScript函數被調用? 我有一個隱藏的股利,說DIV1基於在選擇字段選擇的值,內DIV1,我有一個只讀文本字段的值被設置爲一個輔助方法返回一個值,該值變得可見。Rails更新PARAMS使用Javascript
這個幫助器方法使用一個取決於Params值的動態find_by,但我猜param Hash在select Changes的值不變時(因爲它不是整頁刷新?)。請,我該如何實現更新,以便當選擇值更改時,新值反映在params散列中。我在form_for標記中有:remote => true。有比我更好的方法嗎?
在軌選擇欄查看
#finance_year
<%=f.select :financeyear, options_for_select(finance_year),{ :include_blank => 'Select a
Financial Year' } %>
,併爲選擇
jQuery ->
$('#finance').hide()
value = "Select a Financial Year"
$('#finance_financeyear').change ->
selected = $('#finance_financeyear :selected').text()
$('#finance').show()
$('#finance').hide() if selected is value
輔助方法
def amount_owed(student)
financeyear = params[:financeyear]
@thisstudent = Finance.find_last_by_user_id(@student.user_id,
:conditions => {:financeyear => financeyear })
if(@thisstudent)
@amount_owed= @thisstudent.amount_owed
else
student.department.amount
end
end
我感謝所有幫助,我希望一個一個onchange事件我能夠聰明地問這個問題。
感謝,很少的修改工作,謝謝〜 – dev 2013-03-02 20:15:37
很高興我參加了您的解決方案。 – 2013-03-02 20:35:15