根据从下拉列表中选择的选项加载Fullcalendar数据库

时间:2019-09-16 08:48:28

标签: javascript ajax laravel fullcalendar fullcalendar-3

当我在下拉列表中选择一个人时,FullCalendar将加载他在数据库中拥有的详细信息

我试图调用另一个控制器函数,但是它给了我错误,因为我没有加载页面索引中使用的变量

<script>
        $(document).ready(function() {

            $('.js-example-basic-single').select2({

            });

            $('.js-example-basic-single').on('change', function(){
                var id = $('.js-example-basic-single').val();

                $.get('attendance/' + id,
                {'id':id}, 
                function(data){

                });
            });
            // page is now ready, initialize the calendar...
            $('#calendar').fullCalendar({
                // put your options and callbacks here
                plugins: [ 'interaction'],
                selectable: true,
                selectHelper: true,
                editable: true,
                events : [
                    @foreach($timesheet as $timesheets)
                    {
                        title : '{{ $timesheets->firstname . ' ' . $timesheets->lastname . ', ' . $timesheets->employee_id }}',
                        start : '{{ $timesheets->date }}',
                        color : 'green',
                        @if ($timesheets->date)
                                end: '{{ $timesheets->date }}',
                        @endif
                    },
                    @endforeach
                    @foreach($leave as $leaves)
                    {
                        title : '{{ $leaves->firstname . ' ' . $leaves->lastname . ', ' . $leaves->leave_type . ', ' . $leaves->leave_status }}',
                        start : '{{ $leaves->date_from }}T00:00:00',
                        @if ($leaves->date_to)
                                end: '{{ $leaves->date_to }}T24:00:00',
                        @endif
                    },
                    @endforeach
                ],
                dayClick: function(date, jsEvent, view){
                    var attendance_date = date.format();

                    console.log(attendance_date);

                    $('#a_date').html(attendance_date);
                    $('#txt_a_date').val(attendance_date);
                },
            });
        });
    </script>

最后一个代码块有效,但是它显示了所有人的所有数据

更新:这是现在我在conttroller和JS中的代码。它显示无法读取属性hasTime的错误

//控制器

    public function attendLoad(){


    $columns = [
        'date AS start',
        'date AS end',
        'employee_id AS id',
        'employee_id AS title' 
    ];
    $timesheets = TimeSheet::with('employee')->get($columns);
    $timesheet = $timesheets->toJson();

    return view('admin.attendance', compact('timesheet'));

  }

 ///JS
 events : [ 
                    {
                        url: '/attendances',
                        error: function() 
                        {
                            alert("error");
                        },
                        success: function()
                        {
                            console.log("successfully loaded");
                        }
                    }

            ],

0 个答案:

没有答案