我对 Rails 很陌生,对 JQuery 很陌生。我正在将 jquery.timepicker 与 rails 一起使用,它需要哈希来阻止给定时间列表中的某些时间范围(即,上午 8 点到下午 6 点之间,下午 1 点到 2 点不可用)。在静态页面上,JQuery 是这样写的:
<script>
$('#someTextfieldPair .time').timepicker({
'timeFormat': 'g:ia',
'disableTimeRanges': [
['11:00am', '12:00pm'],
['3:00pm', '4:00pm']
]
});
</script>
我试图根据值@other_events.time_start 和@other_events.time_end 创建散列,而不是静态时间。我试过这个,但我真的不知道如何结合 JQuery 和 rails。
<script>
$('#someTextfieldPair .time').timepicker({
'timeFormat': 'g:ia',
'disableTimeRanges': [
<%= @other_events.each do |e| %>
['<%= e.time_start.strftime("%l:%M %P") %>', '<%= e.time_end.strftime("%l:%M %P") %>'],
<%end %>
]
});
</script>
我正在使用这个 jquery.timepicker:http: //jonthornton.github.io/jquery-timepicker/