问题:
I have been trying to add this jquery plugin to a react project I am working on. I have been trying the different configs I have found in SO and the react documentation, bu...
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
I have been trying to add this jquery plugin to a react project I am working on. I have been trying the different configs I have found in SO and the react documentation, but I can't find a way to make it work without freezing my development set up.
I have tried to import TimePicker from 'timepicker' as a react component and the integrating other libraries page options.
I would need to be able to retrieve the time written or selected by the user in a string format to be able to split it and send it to the back end.
Here is the plugin I am trying to use:
https://github.com/jonthornton/jquery-timepicker
回答1:
Problem solved:
import React, { Component } from 'react';
import $ from 'jquery';
import timepicker from 'timepicker'
class TimePicker extends Component {
componentDidMount(){
this.initDatepicker();
}
initDatepicker(){
$(this.refs.timepicker).timepicker();
}
handleChange = (e) => {
console.log(e.currentTarget.value)
}
render(){
return (
<div>
<input className='timepicker' type='text' ref='timepicker' onBlur={e => this.handleChange(e)} />
</div>
)
}
}
export default TimePicker;