1 回答

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊
實(shí)現(xiàn)此目的的最佳方法是將事件用作完整日歷文檔中描述的JSON 提要模式。
本質(zhì)上它的工作原理是這樣的:如果您告訴 fullCalendar 控制器操作的 URL,每當(dāng)日歷中的日期范圍發(fā)生變化時(shí)(并且它還沒(méi)有下載該日期范圍的事件),它就會(huì)自動(dòng)向服務(wù)器發(fā)出新請(qǐng)求。它還會(huì)自動(dòng)將“開(kāi)始”和“結(jié)束”日期參數(shù)附加到請(qǐng)求中 - 因此您的服務(wù)器所要做的就是讀取這些參數(shù)并在數(shù)據(jù)庫(kù)查詢(xún)中使用它們來(lái)過(guò)濾返回到日歷的結(jié)果。您還可以選擇將其他相關(guān)數(shù)據(jù)附加到請(qǐng)求中 - 例如其他過(guò)濾器選項(xiàng)。
因此,在您的情況下,您最終會(huì)得到如下代碼:
JavaScript - fullCalendar 事件配置:
events: {
? type: "POST",
? url: "/home/GetEvents",
? data: function () { // a function that returns an object
? return {
? ? //your filter object goes here
? };
}
控制器:
[HttpPost]
public JsonResult GetEvents(FiltModel model) {
? ?//...where the FiltModel class includes start and end parameters - ideally these should be DateTime objects, not strings.
? ?//... then, query the database using the filter options in the model, and return JSON in the format required by fullCalendar
}
添加回答
舉報(bào)