小编Ser*_*eyB的帖子

React Datepicker(无法获取输入值)

我是新的反应.我需要使用react-datepicker

我希望在更改日期时获得输入值.如果我点击2017年10月20日,我想把2017年10月20日放在我的变量中.但是我应该使用组件而不是输入的主要问题.

在我从国家获得价值之前.喜欢this.state.value.但是现在它是状态中的对象(时刻).而且这个对象没有值字段.

有我的代码:

export default class DatePicker extends Component {
constructor (props) {
    super(props);
    // this.props.date should looks like "29 November 2017 00:00"
    // second argument for moment() it is format of date, because RFC 2822 date time format
    this.state = {
        date: moment(this.props.value, 'LLL')
    };
}
handleChange = (date) => {
  // const valueOfInput = this.state.date  <--- I want string with date here
  console.log('this.state.date',this.state.date);
  this.setState({date: date});
};
render() {
    return <Form.Field>
              <Label>
                <Picker
                  selected={this.state.date}
                  onChange={this.handleChange}
                  dateFormat="LLL"
                  locale={this.props.language} …
Run Code Online (Sandbox Code Playgroud)

datepicker reactjs react-redux

8
推荐指数
2
解决办法
1万
查看次数

我如何编写自己的`reduce`函数?

我想reduce自己写.但在过去的4个小时里,我做不到.

var a = [10, 21, 13, 56];

function add(a, b) { return a + b }
function foo(a, b) { return a.concat(b) }

Array.prototype.reduce2 = function () {
  // I do not understand how to handle the function of the inlet
  // I know that I should use arguments, but I don't know how many arguments there will be
  var result = 0;
  for(var i = 0; i < arguments.length; i++) {
    result += arguments[i];
  }
 return …
Run Code Online (Sandbox Code Playgroud)

javascript

7
推荐指数
2
解决办法
2256
查看次数

标签 统计

datepicker ×1

javascript ×1

react-redux ×1

reactjs ×1