我正在尝试在我正在编写的 React 组件中使用jQuery UI Timepicker Addon 。但是,每当我尝试使用它时,我都会收到一个错误,即插件添加到 jQuery 的“datetimepicker”函数未定义。
我认为我遇到的部分(或全部)问题是 React 中没有用于此的模块,但我正在通过 React 导入 jQuery。我正在尝试做的...
索引.html:
<!DOCTYPE html>
<html lang='eng'>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- jQuery UI core CSS -->
<link rel="stylesheet" href="dist/jquery-ui.css">
<!-- jQuery UI Timepicker Addon CSS -->
<link rel="stylesheet" href="dist/jquery-ui-timepicker-addon.css">
</head>
<body>
<p style="color: white">
If you see this there is a problem with React on the site.
</p>
<script src="dist/bundle.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/jquery-ui-timepicker-addon.js"></script>
</body>
</html>
如您所见,由于该插件当前不作为 React 组件存在(至少,如果存在,我找不到它),我手动将它与 jQuery UI 一起导入。
我的组件(通过不同的组件包含在索引中):
/** @jsx React.DOM */
var React = require('react');
var jQ = require('jquery');
var Time = React.createClass({
componentDidMount: function() {
jQ('#startDate').datetimepicker({
timeFormat: "HH:mm:ss",
onClose: function() {
console.log("Timepicker closed");
}
});
},
render: function() {
return (
<input id="startDate" className="input-xs datetime modern" type="datetime-local" />
);
}
});
module.exports = {Time: Time};
我应该如何在这个 React 组件中包含 Timepicker 插件?
旁注:我使用 Timepicker 在很大程度上是因为它在其他元素上弹出的效果很好,并且它包含对秒和各种时间格式的支持。我现在正在使用“datetime-local”输入,但他们并没有真正削减它:(