Calendar-PhoneGap-Plugin问题

时间:2014-01-19 12:45:42

标签: javascript android cordova phonegap-plugins

这里有几个问题,但我找不到问题。 我是Javascript等的新手,所以请耐心等待。

我正在尝试创建一个包含一些输入字段的页面,人们可以在其中添加信息,例如标题,日期,时间等然后将其添加到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>

1 个答案:

答案 0 :(得分:1)

添加deviceready事件。它应该工作。

注意:如果您使用的是phonegap版本,则无需包含Calendar.js文件。 Phonegap build会自动添加它。您所需要的只是在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);