亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

.net core Fullcalendar 通過給定月份獲取數據

.net core Fullcalendar 通過給定月份獲取數據

動漫人物 2023-09-28 16:51:27
我們將 fullcalendar 與 .net core-ef core 結合使用。我們通過將其傳遞到 fullcalendar 來獲取所有事件數據。這意味著有很多事件。然后它會在本月默認使用這些數據創建事件日歷。我想要的是讓它變得懶惰。獲取數據時,它只會返回給出月份的事件。在 c# 中public JsonResult GetEvents(E_Model model){     var list = _Service.GetEvents().ToList();   }在js ajax調用文件中function GetEvents() {          var events = [];        $.ajax({            type: "POST",            url: "/calHome/GetEvents",            data: { model: data },            success: function (data) {                calender.style.display = 'block';                          $.each(data, function (i, v) {                                           events.push({                        id: v.id,                        title: v.name,                        description: v.description,                    //i got start and end moment             start: moment(v.start),                    end: v.end != null ? moment(v.end) : null,});        })        GenerateCalender(events);}生成日歷function GenerateCalender(events) {    $('#calender').fullCalendar('destroy');    $('#calender').fullCalendar({        contentHeight: 800,        firstDay: 1,        defaultDate: new Date(),        timeFormat: 'HH:mm', eventLimit: true,        events: events,}ajax GetEvents 在控制器中調用 GetEvents,它返回 json,然后 ajax 中的 GetEvents 調用 genaretecalendar。在aja中調用GetEvents方法時。我想在按下上一個或下一個按鈕時做到這一點,它將向控制器提供月份并按月獲取數據。我嘗試聽上一個事件,例如$('.fc-prev-button').one('click',function (e) {                console.log('prev, do something');            });       新的 events: {            type: "POST",            url: "/home/GetEvents",            data: function () { // a function that returns an object                return {                                     };            }控制器[HttpPost] public JsonResult GetEvents(FiltModel model)                               //model includes string start, end
查看完整描述

1 回答

?
忽然笑

TA貢獻1806條經驗 獲得超5個贊

實現此目的的最佳方法是將事件用作完整日歷文檔中描述的JSON 提要模式。

本質上它的工作原理是這樣的:如果您告訴 fullCalendar 控制器操作的 URL,每當日歷中的日期范圍發生變化時(并且它還沒有下載該日期范圍的事件),它就會自動向服務器發出新請求。它還會自動將“開始”和“結束”日期參數附加到請求中 - 因此您的服務器所要做的就是讀取這些參數并在數據庫查詢中使用它們來過濾返回到日歷的結果。您還可以選擇將其他相關數據附加到請求中 - 例如其他過濾器選項。

因此,在您的情況下,您最終會得到如下代碼:

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

}


查看完整回答
反對 回復 2023-09-28
  • 1 回答
  • 0 關注
  • 198 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號