2014-03-04 52 views
0

我目前正在研究一個需要調度日曆作爲核心功能的學校項目。但是,我從網上下載了第三方Java腳本日曆,並根據我的項目要求編輯了Java腳本代碼。將JavaScript對象存儲到SQL服務器中

但作爲asp.net中的noob,我不知道如何將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

轉換你的對象JSON字符串與JSON.stringify(object),並將其保存在數據庫中,那麼當你訪問數據並恢復這個字符串,您發送的客戶端和解析與JSON.parse (string)

+0

而是一個JSON對象我如何將這個對象與json轉換? – user3377199

+0

究竟你需要在數據庫中存儲哪些數據? – JpBaena13