我试图创建一个倒数计时器,并由于某种原因,使得每个这些倒计时的类独特。我所有的倒计时都是相同的,尽管它们都是不同的due_dates。列表倒计时计时器列表给每个列表项相同的计时器结果轨道
在我的console.log(reservation.duedate)我得到不同的due_dates这是正确的,它是假设。
倒计时对于js中的倒计数函数中的每个列表都使用due_date的第一个结果。这是不正确的;每个列表项目的每个倒计时必须是分开的。
这是your_essays方法在reservations_controller:
@reservations_pending = user.reservations.where("turned_in = ?", false).where("completed = ?", false).where("due_date >= ?", DateTime.now).order(created_at: :desc).page(params[:page_pending]).per_page(3)
your_essays.html.erb:
<div id="content-load-more-pending">
<%= render 'your_essays_pending', reservations_pending: @reservations_pending %>
</div>
这是your_essays.html.erb内的部分称为_your_essays_completed.html.erb
<% reservations_pending.each do |reservation| %>
<div style="color:blue;" class="countdown-class"></div>
<script type="text/javascript">
$(".countdown-class")
.countdown("<%= reservation.due_date %>", function(event) {
$(this).text(
event.strftime('%D days %H:%M:%S')
);
});
console.log("<%= reservation.due_date %>");
</script>
<% end %>
这里CONSOLE.LOG(事件)和的console.log(” <%=保留。 due_date%>“);
实际上是被传递给javascript函数是什么事件? (你可以console.log吗?) –
你的实现有一个错误。您正在更新每行中当前数据的整个类别......这不是您应该如何执行的。 –
我在问题中添加了console.log(event)图片以显示我在控制台中看到的内容。事件的第一个日期不同,然后所有的日期都显示相同的日期。 –