2

我正在使用适用于 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();
    });
});

除了文档中显示的常用示例之外,是否有任何链接可以让我看到如何使用此插件的示例?

4

1 回答 1

5

您必须做的事情是改变DatePickerPlugin.java,因为如果不使用新的Cordova 2.0将无法正常工作。更改此文件中的两行后,调用 fromJavascript不会再麻烦您了。改变:

  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

于 2012-10-01T08:49:11.950 回答