3
對不起,這個最可能的簡單問題。我想添加一些自定義的JSON
數據到fullCalendar並在我的dayClick回調函數中使用它。更具體地說,我想在dayClick中訪問和更改customData上的元素。但我無法弄清楚如何做到這一點。是否可以不更改全日制的源代碼?在dayclick回調中訪問fullCalendar JSON customData
感謝很多提前 延
$('#calendar').fullCalendar({
....
firstDay: 1,
customData: { foo: 'bar', more: 'baz' },
dayClick: function(date, allDay, jsEvent, view) {
// Within the callback function, this is set to the <td> of the clicked day.
var t = $(this);
var foo = customData.foo; // does not work
customData.more = 'foo'; // does not work
// Change the day's background color
if (t.hasClass('badge-important') && foo == 'bar') {
t.removeClass('badge-important');
} else {
t.addClass('badge-important');
}
},
});
酷!非常感謝你的工作。我甚至能夠離開「customData:customData」作業。但我不明白。很明顯,我的customData定義不會導致customData變量。爲什麼不?爲什麼我必須在fullCalendar之外定義customData變量? fullCalendar的事件定義不在外部定義。無論如何,再次感謝! – user1824110
好吧,也許這是另一個問題,但答案只是「範圍」。將'customData:'看作fullCalendar內部函數的一個參數。這個參數的範圍將限制這個內部函數,因此另一個內部函數'dayClick'將無法訪問它。順便說一句,如果一個答案是正確的標記它,否則stackoverflow不會知道你的問題已經解決。考慮提供有用的答案。乾杯 –
謝謝!我是新的stackoverflow。對不起,我沒有足夠的因果關係點來支持你非常有幫助的回答和評論。 – user1824110