2014-01-19 81 views
0

這裏有幾個問題,但是我找不到答案。 我是Javascript新手,請耐心等待。Calendar-PhoneGap-Plugin問題

我正在嘗試製作一個頁面,其中有一些輸入字段,用戶可以在其中添加信息,例如標題,日期,時間等,然後將其添加到Android或iOS本機日曆中。

我不認爲安裝步驟在https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin

最大盡管如此,我相信我安裝了插件,但我怎麼現在都搞不定?

下面是一些代碼:

<script src="js/jquery.js"></script> 
    <script src="js/jquery.mobile-1.3.2.min.js"></script> 
    <script src="js/Calendar.js"></script> 
    <script type="text/javascript" charset="utf-8"> 
      function createMyEvent(){ 
       var cal = new calendarPlugin(); 

       console.log("creating event"); 
       var title= "My Sample Appt"; 
       var location = "Los Angeles"; 
       var notes = "This is a sample note"; 
       var startDate = "2014-01-20 09:30:00"; 
       var endDate = "2014-01-20 12:30:00"; 
       var errCall = function(theerror) { 
        console.log("Error occurred - " + theerror); 
       } 
       var succCall = function(themessage) { 
        console.log("Success - " + themessage); 
       } 
       cal.createEvent(title,location,notes,startDate,endDate, succCall, errCall); 
      } 
     </script> 

... ...

<div data-role="content"> 
<a data-role="button" data-icon="plus" data-iconpos="right" onclick="createMyEvent();"> 
     Add Event 
     </a> 

      <script type="text/javascript"> 
      app.initialize(); 
      </script> 
</div> 
+0

你應該閱讀插件的readme.md中的用法部分 – QuickFix

回答

1

添加deviceready事件。它應該工作。

注意:如果您使用phonegap構建,那麼你不需要包含Calendar.js文件。 Phonegap構建自動添加它。您所需要的只是在config.xml中添加follwoing

<gap:plugin name="nl.x-services.plugins.calendar" /> 

這裏是創建事件的函數。

 function createMyEvent(){ 
      var cal = new calendarPlugin(); 

      console.log("creating event"); 
      var title= "My Sample Appt"; 
      var location = "Los Angeles"; 
      var notes = "This is a sample note"; 
      var startDate = "2014-01-20 09:30:00"; 
      var endDate = "2014-01-20 12:30:00"; 
      var errCall = function(theerror) { 
       console.log("Error occurred - " + theerror); 
      } 
      var succCall = function(themessage) { 
       console.log("Success - " + themessage); 
      } 
      cal.createEvent(title,location,notes,startDate,endDate, succCall, errCall); 
     } 
document.addEventListener("deviceready", Calendar_Add, false);