【发布时间】:2013-02-24 13:46:32
【问题描述】:
我正在使用 Phonegap 构建一个 Android 应用程序,我发现 this plugin 我决定将其用于我的日期选择器字段。我按照说明进行操作,但运行时遇到问题。
这是我的代码:
HTML:
<label for="schedule_start">Start date</label>
<input type="text" class="nativedatepicker" id="schedule_start" name="schedule[start_date]" value="{{start_date}}" required />
JS(我正在使用 Backbone.js)
FormView.prototype.defaultEvents = {
'focus .nativedatepicker': 'focusDatepicker'
};
// call when input focused
FormView.prototype.focusDatepicker = function(e) {
var currentField = $(this);
var myNewDate = Date.parse(currentField.val()) || new Date();
if(typeof myNewDate === "number"){ myNewDate = new Date (myNewDate); }
// 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();
});
};
在创建com.phonegap.plugin 包后,我已将datePickerPlugin.js 添加到/assets/www/js/,并将DatePickerPlugin.java 添加到/src/com/phonegap/plugin/。
我想我在调用 datePickerPlugin.js 时可能会遇到一些问题,因为我没有收到我在文件中放入的警报,但我不确定如何解决。
提前致谢。
【问题讨论】:
-
您的 index.html 文件中是否包含 datepickerplugin.js 文件且路径正确?
标签: java android cordova backbone.js datepicker