Web app - slider showing days of the months feature

前端 未结 3 1446
臣服心动
臣服心动 2021-02-08 13:43

For a school project we have to build a web app. I\'ll be creating something where people can keep track of their classes, their homework, and their free time. A planner/calenda

3条回答
  •  一生所求
    2021-02-08 14:01

    This seems pretty straight forward to me. I don't really have time to write the whole thing now. but heres what steps I would take.

    1) create a model which gets all the tasks for a month, and uses that to create an array of {date}=>{num_tasks} e.g. {'1'=>3,'2'=>1, "3"=>0, ...}. //hint: use a regular SQL count OR just loop thru and tally them.

    2) create a controller function to return this array as JSON. Something like this:

    public function get_month($month, $year) {
        $tasks = $this->task_model->get_each_days_taskcount($month, $year);
        $json = json_encode ($tasks);
        echo $json;
    }
    

    3) write a html page which has a javascript function to call this controller function with AJAX. Something like:

    function fill_calendar(month, year) {
    $.get('some_controller/get_month/' + month + '/' + year, function(data) {
        // parse the JSON then
        // do something with the data here like $('#calendar').append();
    });
    }
    

    4) Load this month with something like this:

    $(function() {
        var d = new Date();
        var tmonth = d.getMonth();
        var tyear = d.getFullYear();
        fill_calendar(tmonth, tyear); // populate with this month
    });
    

    5) make the prev and next buttons work with something like

    $('#prev_button').click(function() {
        fill_calendar(current_month - 1 , tyear);
        // you will probly need to make this calculation smarter than just minus 1
    });
    

提交回复
热议问题