FullCalendar不刷新按钮在asp.net中的事件

时间:2018-07-21 10:24:56

标签: javascript fullcalendar

我正在尝试从数据库中获取事件并附加在完整日历上。为此,我使用了一个下拉列表,列出了几个月和一年。从下拉列表中选择月份并单击搜索按钮后,事件将添加到日历中。但是,当我尝试从下拉列表中更改月份,然后单击搜索按钮时,从数据库中正确地获取了所选数据,但保留了旧事件,并且不刷新新的月份事件。下面是我的代码。

EventCalendar.aspx

<script>

    $(document).ready(function () {

        $("#searchBtn").click(function () {

           var month = $('#ContentPlaceHolder2_DropDownMonth option:selected').val();
           var user = $('#ContentPlaceHolder2_DDUser option:selected').val();
           alert(month.split(" ")[0]);
           var monthname = month.split(" ")[0];
           var year = month.split(" ")[1];

           var monthd = new Date(Date.parse(monthname + "1", year)).getMonth() + 1
           var date = year + "-" + monthd + "-" + "1"
           console.log(monthd)

                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "NewUserScore.aspx/GetScoreDetails",
                    data: "{ 'userId':'" + user + "', 'month':'" + month + "'}",

                    success: function (result) {

                        events_array = [];

                        $.each(result.d, function (key, value)
                        {
                            if (value.start != null) {
                                events_array.push(
                                {
                                    title: value.title,
                                    start: value.start
                                });
                            }
                       });

                        console.log(events_array)



                            $('#calendar').fullCalendar({

                                theme: true,

                                header: {
                                    left: 'prev,next today',
                                    center: 'title',
                                    right: 'month,agendaWeek,agendaDay'
                                },

                                defaultDate: date,
                                displayEventTime: false,
                                events: events_array,


                                dayClick: function (date, jsEvent, view) {


                                    $.ajax({
                                        type: "POST",
                                        contentType: "application/json; charset=utf-8",
                                        url: "NewUserScore.aspx/GetScoreDetailsForDate",
                                        data: "{ 'date':'" + date.format() + "', 'userId':'" + user + "'}",
                                        success: function (result) {

                                            $("#tblScore td").remove();

                                            var tblEmployee = $("#tblScore");

                                            $.each(result.d, function (index, item) {

                                                var tr = $("<tr></tr>");

                                                tr.html(("<td> <button type=\"button\" id=" + item.Id + "  class=\"btnEdit\" data-toggle=\"modal\" data-target=\"#dialog-transaction\">Edit</button> </td>")
                                                + " " + ("<td><button type=\"button\" id=" + item.Id + "  class=\"btnDelete\">Delete</button></td>")
                                                + " " + ("<td>" + item.scoreDate + "</td>")
                                                + " " + ("<td>" + item.uUser.struserName + "</td>")
                                                + " " + ("<td><a href =\"Case.aspx?id=" + item.cCase.strId + "\" target=_blank>" + item.cCase.strTitle + "</a> </td>")
                                                + " " + ("<td>" + item.pProject.strProjName + "</td>")
                                                + " " + ("<td>" + item.CaseScore + "</td>"));

                                                tblEmployee.append(tr);

                                            });
                                         }
                                    });
                                },


                            });

                            $('#calendar').fullCalendar('gotoDate', date);
                            $('#calendar').fullCalendar('refetchEvents');

                     }
                });
        });
    });



</script>

-更新-

$("#searchBtn").click(function () {

           var month = $('#ContentPlaceHolder2_DropDownMonth option:selected').val();
           var user = $('#ContentPlaceHolder2_DDUser option:selected').val();
           alert(month.split(" ")[0]);
           var monthname = month.split(" ")[0];
           var year = month.split(" ")[1];

           var monthd = new Date(Date.parse(monthname + "1", year)).getMonth() + 1
           var date = year + "-" + monthd + "-" + "1"
           console.log(monthd)


                  $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "NewUserScore.aspx/GetScoreDetails",
                    data: "{ 'userId':'" + user + "', 'month':'" + month + "'}",

                    success: function (result) {

                        events = [];

                        $.each(result.d, function (key, value)
                        {
                            if (value.start != null) {
                                events.push(
                                {
                                    title: value.title,
                                    start: value.start
                                });
                            }
                       });

                        console.log(events)

                        $("#calendar").fullCalendar('refetchEvents', events);
                    }
                });
        });


<script>

    $(document).ready(function () {

                $('#calendar').fullCalendar({

                theme: true,
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                },


                displayEventTime: false,
                //events: events_array,


                dayClick: function (date, jsEvent, view) {


                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "NewUserScore.aspx/GetScoreDetailsForDate",
                        data: "{ 'date':'" + date.format() + "', 'userId':'" + user + "'}",
                        success: function (result) {

                            $("#tblScore td").remove();

                            var tblEmployee = $("#tblScore");

                            $.each(result.d, function (index, item) {

                                var tr = $("<tr></tr>");

                                tr.html(("<td> <button type=\"button\" id=" + item.Id + "  class=\"btnEdit\" data-toggle=\"modal\" data-target=\"#dialog-transaction\">Edit</button> </td>")
                                + " " + ("<td><button type=\"button\" id=" + item.Id + "  class=\"btnDelete\">Delete</button></td>")
                                + " " + ("<td>" + item.scoreDate + "</td>")
                                + " " + ("<td>" + item.uUser.struserName + "</td>")
                                + " " + ("<td><a href =\"Case.aspx?id=" + item.cCase.strId + "\" target=_blank>" + item.cCase.strTitle + "</a> </td>")
                                + " " + ("<td>" + item.pProject.strProjName + "</td>")
                                + " " + ("<td>" + item.CaseScore + "</td>"));

                                tblEmployee.append(tr);

                            });
                        }
                    });
                },

            });
                //$('#calendar').fullCalendar('gotoDate', date);
      });

</script>

0 个答案:

没有答案