将JavaScript对象存储到SQL Server中

时间:2014-03-04 02:01:22

标签: javascript

我目前正在开展一个学校项目,需要一个日程安排日历作为核心功能。但是,我从网上下载了第三方java脚本日历,并根据我的项目要求编辑了java脚本代码。

但是作为asp.net中的菜鸟,我不知道如何将javascript对象保存到我的SQL服务器中。是否有指南或网站,我可以学习如何做到这一点?下面是我的一组java脚本,那么如何在这段代码中使用JSON?

$(document).ready(function () {


    /* initialize the external events
    -----------------------------------------------c ------------------*/

    $('#external-events div.external-event2').each(function () {

        // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
        // it doesn't need to have a start or end
        var eventObject = {
            title: $.trim($(this).text()) // use the element's text as the event title
        };

        // store the Event Object in the DOM element so we can get to it later
        $(this).data('eventObject', eventObject);

        // make the event draggable using jQuery UI
        $(this).draggable({
            zIndex: 999,
            revert: true,      // will cause the event to go back to its
            revertDuration: 0  //  original position after the drag
        });






    });







    /* initialize the external events
    -----------------------------------------------c ------------------*/

    $('#external-events div.external-event').each(function () {

        // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
        // it doesn't need to have a start or end
        var eventObject = {
            title: $.trim($(this).text()) // use the element's text as the event title
        };

        // store the Event Object in the DOM element so we can get to it later
        $(this).data('eventObject', eventObject);

        // make the event draggable using jQuery UI
        $(this).draggable({
            zIndex: 999,
            revert: true,      // will cause the event to go back to its
            revertDuration: 0  //  original position after the drag
        });






    });


    /* initialize the calendar
    -----------------------------------------------------------------*/

    var calendar = $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },

        selectable: true,
        selectHelper: true,
        select: function (start, end, allDay) {
            var title = prompt('Event Title:');
            if (title) {
                calendar.fullCalendar('renderEvent',
                    {
                        title: title,
                        start: start,
                        end: end,
                        allDay: allDay
                    },
                    true // make the event "stick"
                );
            }
            // calendar.fullCalendar('unselect');
        },




        eventClick: function (calEvent, jsEvent, view) {


            var title = prompt('Rename Event Title:');

            calEvent.title = title;
            // copiedEventObject.title = title;
            alert('Altered Event : ' + calEvent.title);


            // change the border color just for fun
            $(this).css('border-color', 'red');

        },







        editable: true,
        droppable: true, // this allows things to be dropped onto the calendar !!!
        drop: function (date, allDay) { // this function is called when something is dropped

            // retrieve the dropped element's stored Event Object
            var originalEventObject = $(this).data('eventObject');


            // we need to copy it, so that multiple events don't have a reference to the same object
            var copiedEventObject = $.extend({}, originalEventObject);

            // assign it the date that was reported
            copiedEventObject.start = date;
            copiedEventObject.allDay = allDay;
            //    copiedEventObject.title = 'abc';     //<<<Change the title



            // render the event on the calendar
            // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
            $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);

            // is the "remove after drop" checkbox checked?
            if ($('#drop-remove').is(':checked')) {
                // if so, remove the element from the "Draggable Events" list
                $(this).remove();
            }

        }
    });


});

1 个答案:

答案 0 :(得分:1)

将对象JSON转换为带有JSON.stringify(object)的String,并将其保存在数据库中,然后当您访问数据并恢复此String时,发送客户端并使用JSON.parse (string)解析JSON对象