Моя домашняя вкладка (Все) просто отлично работает, но когда я перехожу на 2-ю вкладку, которая является содержимым div, diffForHumans () больше не будет работать. это код из моей модели:
protected $dates = ['schedule'];
и это из моего home.blade.php:
<div class="time">
@if($match->status == 'ongoing')
<span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px"> LIVE</span>
@elseif($match->status == 'settled')
{{$match->schedule->diffForHumans()}} <span style="color: #606060; font-weight: bold; font-size: 16px"> SETTLED</span>
@elseif($match->status == 'draw')
{{$match->schedule->diffForHumans()}} <span style="color: #606060; font-weight: bold; font-size: 16px"> DRAW - CREDITS RETURNED</span>
@else
<strong class="match_countdown" data-schedule="{{$match->schedule}}">{{$match->schedule->diffForHumans()}}</strong>
@endif
</div>
и это из моего dota.blade.php
<div class="time">
@if($match->status == 'ongoing')
<span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px"> LIVE</span>
@elseif($match->status == 'settled')
{{$match->schedule->diffForHumans()}} <span style="color: #606060; font-weight: bold; font-size: 16px"> SETTLED</span>
@elseif($match->status == 'draw')
{{$match->schedule->diffForHumans()}} <span style="color: #606060; font-weight: bold; font-size: 16px"> DRAW - CREDITS RETURNED</span>
@else
<strong class="match_countdown" data-schedule="{{$match->schedule}}">{{ \Carbon\Carbon::parse($match->schedule)->diffForHumans() }}</strong>
@endif
</div>
и это сценарий:
<script>
$(function(){
var now = moment(moment().format('YYYY-MM-DD'));
var to_tournament_date = moment("2017-08-03T00:00:00+08:00").fromNow();
$('.tournament-winner-timer').html(to_tournament_date);
})
$(document).ready(function() {
$.each($('.match_countdown'), function(key, index) {
countdown(this, $(this).data('schedule'));
});
function countdown(element, time) {
var countDownDate = parseInt(moment(time).format('x'));
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
element.innerHTML = (days > 0 ? days + "d " : "") + (hours > 0 ? hours + "h " : "") + (minutes > 0 ? minutes + "m " : "") + seconds + "s from now";
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
element.innerHTML = "Match will start soon";
}
}, 1000);
}
так что в принципе, на самом деле нет никакой разницы. из моей домашней вкладки Blade, он просто отлично работает, и у них одинаковые сценарии, в моем доме он отображает 3 дня 2 часа 46 секунд, а когда время по расписанию достигает 0, он переключается в состояние «Матч скоро начнется» так что теперь, на моей вкладке Dota это не работает так же. есть идеи почему?