Time picker set up in React - jquery-timepicker

问题: 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;
  • 发表于 2019-01-18 04:00
  • 阅读 ( 191 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除