我正在使用"xdan/datetimepicker" v2.5.4。
在 webpack.config.js 我有:
...
module: {
loaders: [
{
test: require.resolve('jquery'), //Latest
loader: 'expose?jQuery!expose?$'
}
]
},
resolve: {
alias: {
"jquery": path.resolve("./node_modules/jquery/dist/jquery.js"),
"jquery.datetimepicker": path.resolve("./node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js")
}
}
在 knockoutBindings.js :
var ko = require('knockout');
require('jquery');
/* Date picker value binder for knockout */
(function (ko) {
ko.bindingHandlers.datetimepicker = {
init: function (element, valueAccessor, allBindingsAccessor) {
var $element = $(element);
var value = valueAccessor(), allBindings = allBindingsAccessor();
var valueUnwrapped = ko.utils.unwrapObservable(value);
var options = allBindings.dtPickerOptions || {};
// The error Message: Unable to process binding "datetimepicker: function (){return timeFrom " Message: $element.datetimepicker is not a function"
$element.datetimepicker({
step: 15,
format: config.timeFormat,
formatTime: config.timeFormatHours,
formatDate: config.timeFormatDate,
onChangeDateTime: function (dp, $input) {
var date = moment($input.val(), config.timeFormat);
date.set('second', 0);
var observable = valueAccessor();
observable(date.format(config.timeFormat));
},
lang: 'custom',
i18n : {
custom: translationController.datePicker
}
});
},
update: function (element, valueAccessor) {
var valueUnwrapped = ko.utils.unwrapObservable(valueAccessor());
var obs = valueAccessor();
$(element).val(moment(valueUnwrapped, config.timeFormat).format(config.timeFormat));
}
};
})(ko);
如何制作" $。fn.datetimepicker"有绑定吗?
我尝试分配变种,我想起了:
//require('jquery.datetimepicker');
//require('imports?this=>window!jquery.datetimepicker');
//require('expose?$.fn.datetimepicker!jquery.datetimepicker');
//$.fn.datetimepicker = require('script!jquery.datetimepicker');
//require('imports?this=>$!jquery.datetimepicker');
//require('expose?$!jquery.datetimepicker');
这些都没有人工作......
注意: Jquery可用,一切都很好......
答案 0 :(得分:0)
发现溶解。 简单的是必须将这种代码的和平添加到" knockoutBindings.js ":
require('exports?$!jquery.datetimepicker');