我想破解fullcalendar以便在我的日曆中顯示每行多個事件。所以爲了做到這一點,我想迭代這些行並重新組織它們的內容。不過,這些行jQuery不能find()
。jQuery沒有找到附加元素
<div class="fc-content-skeleton">
<table>
<thead>
<tr>
<td class="fc-day-number fc-mon fc-past" data-date="2016-09-26">26</td>
<td class="fc-day-number fc-tue fc-past" data-date="2016-09-27">27</td>
<td class="fc-day-number fc-wed fc-past" data-date="2016-09-28">28</td>
<td class="fc-day-number fc-thu fc-past" data-date="2016-09-29">29</td>
<td class="fc-day-number fc-fri fc-today fc-state-highlight" data-date="2016-09-30">30</td>
<td class="fc-day-number fc-sat fc-other-month fc-future" data-date="2016-10-01">1</td>
<td class="fc-day-number fc-sun fc-other-month fc-future" data-date="2016-10-02">2</td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2"></td>
<td class="fc-event-container" rowspan="2">
<a class="fc-day-grid-event fc-h-event fc-event fc-start fc-end event-free" data-url=""></a>
</td>
<td rowspan="2"></td>
<td class="fc-event-container">
<a class="fc-day-grid-event fc-h-event fc-event fc-start fc-end event-mine" data-url=""></a>
</td>
<td class="fc-event-container">
<a class="fc-day-grid-event fc-h-event fc-event fc-start fc-end event-free" data-url=""></a>
</td>
<td rowspan="2"></td>
<td rowspan="2"></td>
</tr>
<tr>
<td class="fc-event-container">
<a class="fc-day-grid-event fc-h-event fc-event fc-start fc-end event-taken" data-url=""></a>
</td>
<td class="fc-event-container">
<a class="fc-day-grid-event fc-h-event fc-event fc-start fc-end event-free" data-url=""></a>
</td>
</tr>
</tbody>
</table>
</div>
我能夠得到table
標籤.fc-content-skeleton
下。但是當我調用'find(「table」)。children()'時,它只返回thead
,但不是我需要的tbody
。在所有事件被提取並追加後,我都這麼做了。
編輯
的函數被調用如下:
$(document).on("ready turbolinks:load", function(){
//.....
$("#calendar").fullCalendar(calendarOpt);
$("#calendar").reorganizeEvents();
//.....
}):
函數本身:
(function($) {
$.fn.reorganizeEvents = function(){
if(reorgHandler == false){
$(this).fullCalendar('render');
var $dayContainers = $(this).find(".fc-row .fc-content-skeleton table")
.children(); //obtaining children of the table in .fc-skeleton.
// Supposed to be <thead> and <tbody>
console.log($dayContainers); //successfully finds table
$dayContainers.each(function(index){
console.log($(this)); //shows only <thead> as a single child
});
reorgHandler = true;
}
}
}(jQuery));
你在哪裏叫這個JavaScript代碼?我的水晶球說你正試圖在元素存在之前訪問這些元素。 – epascarello
@epascarello這個,或者它也可以在它們存在之前使用一個變量值。取決於何時寫入find()...。 – krillgar
@epascarello我在'document.ready'函數中實例化fullcalendar後,在'$(「#calendar」)'上調用它。 – mityakoval