Cordova / Phonegap日历插件iOS创建活动

时间:2014-03-20 04:51:04

标签: javascript ios cordova

我正在使用此处找到的Cordova / Phonegap插件:

https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin

我的应用是一个每天都有不同事件的RSS源,我想更改javascript代码,以便用户能够添加到日历,函数至少会读取标题日期。

在我的main.js中,函数是:

 function Calendar_Add(){
  // prep some variables

   var startDate = new Date("March 18, 2014 13:00:00");
   var endDate = new Date("March 18, 2014 14:30:00");
   var title = "Event Added!";
   var location = "Home";
   var notes = "Some notes about this event.";

   var success = function(message) { alert("Success: " + JSON.stringify(message)); };
   var error = function(message) { alert("Error: " + message); };

   // create
  window.plugins.calendar.createEventWithCalendar(title,location,notes,startDate,endDate,success,error);    
 }

这是创建一个事件,但我再次遇到变量问题。这是我试过的完整的javascript页面:

//jQuery get target page
function IE_navigate(index) {

Bindex = index;

$.mobile.changePage('#eventPage', 'slidefade');

$.each(data, function(i,item){
    if (i == Bindex) {
          //Clear if page was previously populated


          //Populate page
          $('#page-title').html(item.title + "<br />");
          $('#page-region').html(item.Region + "<br />");
          $('#page-content').html(item.fullInfo + "<br />");

            /*                  
             startDate = new Date(item.Date);
             endDate = new Date(item.Date);
             title = item.title;
             place = item.Region;

             */
          $(this).ready(function(e) {
              $('#page-content').on('click','a', function(e){
                e.preventDefault();
                currentPage = $(this).attr('href');
               window.open(currentPage, '_system', 'location=yes')
           });
          });
         // return false;

          return false
    }
});
};

 var Aindex = "";
var Bindex = "";
var data = [];

$(function () { Load_Content() });

function Load_Content() {

    $('#feed').empty(); 
    data = [];
$.ajax({
        type: 'GET',
        url:'http://www.e-grid.net/BayAreaTech/wp-rss2.php?cat=1',
        dataType: 'xml',
        success: function (xml) {
            $('#header-title').html("e-Grid Mobile");
                $(xml).find("item:lt(60)").each(function () {

                var dateText = $(this).find("Date").text().toString();
                var eventDate = moment(dateText,"YYYY-MM-DD");
                var title = $(this).find("title").text();
                var region = dateText.substr(8).toUpperCase();
                  if (region == "SCV") { region = "Santa Clara  Valley";}
                  if (region == "OEB") { region = "Oakland/East Bay";}
                  if (region == "SF") { region = "San Francisco";}
                  if (region == "ALL") { region = "All regions";} 
                var description = $(this).find("description").text();
                var infoDisplay = description.substr(0,     description.indexOf(",")+120) + "..."; //Parsed DATE from description
                var fullDescription = $(this).find('encoded').text();    
                var category = $(this).find("category").text();
                var linkUrl = $(this).find("link").text();
                var displayTitle = title; 

                var item = {title: displayTitle, 
                            link: linkUrl, 
                            infoDescription: infoDisplay, 
                            Date: new Date(eventDate), 
                            Region: region, 
                            fullInfo: fullDescription,}

                var now = moment().subtract('days', 1);
                if (item.Date >= now){ data.push(item); }

                });

                 data.sort(function (a, b) {
                    a = new Date(a.Date);
                    b = new Date(b.Date);
                    return a<b ? -1 : a>b ? 1 : 0;
                 });

                 if (data.length > 0) {
                    $.each(data, function (index, item) {

                          Aindex = data.indexOf(this)

                          var h_feedList =  '<li';
                          h_feedList += '><a href="#" onclick="IE_navigate(' + Aindex + ')" target="_blank">';
                          h_feedList += '<h3>';                             // Start  Title Text
                          h_feedList += item.title;                     // Title Text
                          h_feedList += '</h3><p>';                         // End the title text - start the description text
                          h_feedList += item.infoDescription;           // Description text
                          h_feedList += '</p>';                         // End description text
                          h_feedList += '</a>';                         // End list link
                          h_feedList += '</li>';                            // End List Item

                         $('#feed').append(h_feedList);

                     });
                 }
                 else
                 {
                     var message = "No upcoming events within your selection; check back soon!";
                     $('#feed').append('<h3>' + message + '</h3>');
                 }
        }
    });
};


function next_event() {
Bindex++;
if (Bindex > data.length){ Bindex = 0; }

$('#page-title').html(data[Bindex].title);
$('#page-region').html(data[Bindex].Region);
$('#page-content').html(data[Bindex].fullInfo); 


 startDate = new Date(data[Bindex].Date);
 endDate = new Date(data[Bindex].Date);
 title = data[Bindex].title;
 place = data[Bindex].Region;
}
function previous_event() {
Bindex--;
if (Bindex <= 0){ Bindex = data.length; }

$('#page-title').html(data[Bindex].title);
$('#page-region').html(data[Bindex].Region);
$('#page-content').html(data[Bindex].fullInfo);

startDate = new Date(data[Bindex].Date);
endDate = new Date(data[Bindex].Date);
title = data[Bindex].title;
place = data[Bindex].Region;

}


$(document).ajaxStart(function() {
  $.mobile.loading('show', {text: 'Loading BayArea Events...', textVisible: true, textonly: true});
});

$(document).ajaxStop(function() {
  $.mobile.loading('hide');
});






$( document ).on( "pagecreate", "#home", function() {
  $( document ).on( "swipeleft swiperight", "#home", function( e ) {
    // We check if there is no open panel on the page because otherwise
    // a swipe to close the left panel would also open the right panel (and v.v.).
    // We do this by checking the data that the framework stores on the page element (panel: open).
    if ( $( ".ui-page-active" ).jqmData( "panel" ) !== "open" ) {
        if ( e.type === "swipeleft" ) {
            $( "#settingspanel" ).panel( "open" );
        } else if ( e.type === "swiperight" ) {
            $( "#fieldpanel" ).panel( "open" );
        }
    }
 });
});
$( document ).on( "pagecreate", "#eventPage", function() {
 $( document ).on( "swipeleft swiperight", "#eventPage", function( e ) { 
         if ( e.type === "swipeleft" ) {
            next_event();
        } else if ( e.type === "swiperight" ) {
            previous_event();
        }
});
});

function Calendar_Add(){
 // prep some variables

 var startDate = new Date(item.Date);
 var endDate = new Date(item.Date);
 var title = item.title;
 var location = item.region;
 var notes = "";

 var success = function(message) { alert("Success: " + JSON.stringify(message)); };
 var error = function(message) { alert("Error: " + message); };

 // create
  window.plugins.calendar.createEventWithCalendar(title,location,notes,startDate,endDate,success,error);    
}

1 个答案:

答案 0 :(得分:0)

Calendar插件不存在函数createEventWithCalendar。您应该使用具有相同参数的createEvent。

如果你在某个地方有这样的函数,你可能会被Javascript错误警告: window.onerror = function(a,b,c){   警报(A);   警报(B);   警报(C); }

希望这可以帮助您让我的插件工作, 涡