javascript - 将 JavaScript 对象存储到 SQL Server

标签 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();
            }

        }
    });


});

最佳答案

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

的 JSON 对象

关于javascript - 将 JavaScript 对象存储到 SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22161429/

相关文章:

javascript - 如何在 javascript/Meteor 中维护内存中的对象和变量?

javascript - 谷歌地图路线出现两次?

JavaScript 语法结构

javascript - React Router 嵌套路由不渲染

javascript - 在 Angular 中构建一个宽度为 100% 的可重用 D3.js 图表?

javascript - jQuery+ PHP 向具有特定值的元素添加新属性

javascript - 留在 anchor #link 的页面顶部

javascript - 使用 withDataAndEvents 的 jQuery.clone() 似乎没有复制数据

javascript - listToArray 的函数(函数(arrayToList(数组)

javascript - 即使页面已经打开,如果 JavaScript 被禁用,如何使 div 突然显示