2012-09-13 48 views
2

我正在使用Android的Phonegap Datepicker插件。Android上的Phonegap Datepicker插件

當我打開屏幕時,我無法看到日期選擇器。我收到這個錯誤。

09-13 22:37:55.894:E/Web控制檯(13123):遺漏的類型錯誤:無法調用未定義的方法 '秀' 的文件:///android_asset/www/index.html:689

我的代碼如下所示:

<div data-role="controlgroup"> 
    <p> 
     <label for="airportName">Airport</label> <input type="text" name="airportName" id="airportName" class="custom" /> 
     <label for="selectDate">Date</label> <input type="text" name="selectDate" id="selectDate" class="nativedatepicker" />    
    </p> 

,我已經使用的事件處理程序像

$('.nativedatepicker').click(function(event) { 
    var currentField = $(this); 
    var myNewDate = Date.parse(currentField.val()) || new Date(); 

    // Same handling for iPhone and Android 
    window.plugins.datePicker.show({ 
     date : myNewDate, 
     mode : 'date', // date or time or blank for both 
     allowOldDates : true 
     }, function(returnDate) { 
      var newDate = new Date(returnDate); 
      currentField.val(newDate.toString("yyyy-MM-dd")); 

      // This fixes the problem you mention at the bottom of this script with it not working a second/third time around, because it is in focus. 
      currentField.blur(); 
    }); 
}); 

是否有任何聯繫,我可以看到這是如何插件從使用分開的例子通常的例子顯示在文檔?

+0

您是否將插件添加到plugin.xml? – Ocelot

+0

是的,我做到了。 – benya

+0

你的phonegap/cordova版本是什麼? – Littm

回答

5

你必須做的事情是改變DatePickerPlugin.java,因爲如果不是新的Cordova 2.0將不起作用。 更改此文件中的兩行後,從Javascript調用不會再次麻煩你。 變化:

final DroidGap currentCtx = (DroidGap) ctx.getContext(); 

此:

final Context currentCtx = cordova.getActivity(); 

找到這個:

ctx.runOnUiThread(runnable); 

和替換:

cordova.getActivity().runOnUiThread(runnable); 

閱讀此線程的詳細信息: datePicker plugin not working in Phonegap 2.0

+0

我更改了你發佈的代碼。我仍然不能得到日期。我使用科爾多瓦2.2.0和相關的JS。你能幫我嗎 ? –