Android上的Phonegap Datepicker插件

ben*_*nya 2 android datepicker cordova

我正在使用Android的Phonegap Datepicker插件.

打开屏幕时,我无法看到日期选择器.我收到了这个错误.

09-13 22:37:55.894:E/Web控制台(13123):未捕获的TypeError:无法在file:///android_asset/www/index.html调用未定义的方法'show':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>
Run Code Online (Sandbox Code Playgroud)

我有使用过的事件处理程序

$('.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();
    });
});
Run Code Online (Sandbox Code Playgroud)

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

mra*_*888 5

你必须做的事情就是改变,DatePickerPlugin.java因为如果没有新的Cordova 2.0将不起作用.更改此文件中的两行后,调用Javascript将不会再次麻烦您.更改:

  final DroidGap currentCtx = (DroidGap) ctx.getContext();
Run Code Online (Sandbox Code Playgroud)

为了这:

  final Context currentCtx = cordova.getActivity();
Run Code Online (Sandbox Code Playgroud)

找到这个:

  ctx.runOnUiThread(runnable);
Run Code Online (Sandbox Code Playgroud)

并替换为:

  cordova.getActivity().runOnUiThread(runnable);
Run Code Online (Sandbox Code Playgroud)

阅读此主题以获取更多信息: datePicker插件在Phonegap 2.0中不起作用