私はカウントダウンタイマーを作成しようとしていますが、何らかの理由でクラスがこれらのカウントダウンを一意にしています。彼らのすべてのdue_datesは同じですが、私のカウントダウンはすべて同じイベントです。リスト上のカウントダウンタイマーは、各リストアイテムに対して同じタイマー結果を与えます。
私のconsole.log(reservation.duedate)には正しいdue_datesとなるものがあります。
countdownは、jsのcountdown関数の各リストに対してdue_dateの最初の結果を使用しています。これは正しくありません。各カウントダウンは各リスト項目ごとに別々にする必要があります。
これはreservations_controllerでyour_essays方法である:
@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>
これは、(イベント)とはconsole.log(」<% =予約CONSOLE.LOGさ
<% 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 %>
_your_essays_completed.html.erb呼ばyour_essays.html.erb内の部分です。 due_date%> ");
何イベント実施例ですか? (console.logはできますか?) –
実装にエラーがあります。あなたはすべての行の現在のデータで全クラスを更新しています...それはあなたがそれを行うべきではありません。 –
コンソールに表示されている内容を表示するために、console.log(event)画像を質問に追加しました。イベントの最初の日付は異なるものとなり、その後はすべて同じ日付を示します。 –