从列表中检索日期并将其显示在FullCalendar中

时间:2012-12-27 08:35:43

标签: jquery fullcalendar

我有一个包含开始日期和结束日期的列表。我正在使用JQuery AJAX检索它。现在,我如何在FullCalendar中将该日期显示为事件。

从列表中检索数据的代码

   var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    <listName>BatchSchedule</listName> \
                    <viewFields> \
                        <ViewFields> \
                           <FieldRef Name='BatchId' /> \
                           <FieldRef Name='StartDt' /> \
                           <FieldRef Name='Enddt' /> \
                           <FieldRef Name='location' /> \
                        </ViewFields> \
                    </viewFields> \
                     <rowLimit>8500</rowLimit>\
                </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>";

    $.ajax({
        url: "https://www.mysite.com/sites/Batch/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    }); // end ajax function

  function processResult(xData, status) 
  {
     $(xData.responseXML).find("z\\:row").each(function() {});
  }

我昨天写的完整代码但没有得到理想的结果

    function getbatchdetails(loc){ //loc - passing location as parameter
var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                     <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>batch</listName> \
                        <viewFields> \
                            <ViewFields> \
                               <FieldRef Name='BatchId' /> \
                               <FieldRef Name='StartDt' /> \
                               <FieldRef Name='Enddt' /> \
                               <FieldRef Name='location' /> \
                               <FieldRef Name='ID' /> \
                            </ViewFields> \
                        </viewFields> \
                         <rowLimit>500</rowLimit>\
                    </GetListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";

        $.ajax({
            url: "https://www.mysite.com/sites/Batch/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        }); // end ajax function
        function processResult(xData, status) 
        {
            $(xData.responseXML).find("z\\:row").each(function() { 
            var returnedloc = new String($(this).attr("ows_location"));
            if(loc==returnedloc){
                newEvent[0]=new String($(this).attr("ows_Title"));
                newEvent[1]=$(this).attr("ows_StartDt");
                newEvent[2]=$(this).attr("ows_Enddt");
                eventsArray.push(newEvent);
              }
            });//responseXML
        var nextEvent = [];
        for (var k=0;k<eventsArray.length;k++){
            nextEvent.push ({
                title: eventsArray[k][0],
                start: eventsArray[k][1],
                end: eventsArray[k][2],
                allDay: false
            });
        }
        $('#calendar').fullCalendar({
            /*defaultView: 'year',
            year: 2012,
            header: {
                left: 'prev,next today',
                center: 'title',
                //right: 'year,month,agendaWeek,agendaDay'
                right: 'year,month'
            },*/
            editable: true,
            events: nextEvent,
            colour: 'blue'
        });       }//processResult
}//end of getBatch Details

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

$("#calendar").fullCalendar('renderEvent',
{
    title: "some title",
    start: eventStart,
    end: eventEnd,
    allDay: allDay
},
true // make the event "stick"

);

请记住,您需要在代码中使用eventStarteventEnd作为JS变量(您可以根据需要调用这些变量)。