【问题标题】:Adding a jquery datepicker to react component添加一个 jquery datepicker 来反应组件
【发布时间】:2016-12-09 09:41:15
【问题描述】:

我正在尝试将日期选择器集成到反应组件中。我正在为日期选择器使用pickaday jquery 库。为了实现这一点,我创建了以下组件。

DatePicker.js.jsx

var DatePicker = React.createClass({
//This is a callback to parent component for updating the state
    changeDuration: function (date) {
        this.props.changeDuration(this.props.id, date);
    },

    componentDidMount: function () {
        _self = this;
        new Pikaday({
            field: document.getElementById(this.props.id),
            format: 'D MMM YYYY',
            onSelect: function () {
                _self.changeDuration(this.getMoment())
            },
            minDate: this.props.minDate
        });
    },


    render: function () {
        return (
            <input type="text" name={this.props.name} id={this.props.id} defaultValue={this.props.value}/>
        )
    }
});

这里的问题是,在第一页加载时,我可以选择日期选择器,它按预期工作,但如果我再次更改它而不重新加载,它将无法工作并在控制台中显示以下错误。

未捕获的类型错误:_self.changeDuration 不是函数

谁能告诉我这里做错了什么?

【问题讨论】:

  • _self = this;应该是 var _self = this;
  • @ved 完全正确..不能相信这是问题所在。从昨天开始我一直在摆弄这个。非常感谢

标签: javascript jquery reactjs datepicker


【解决方案1】:

错误是你的变量没有类型声明。

_self = this;

应该是

var _self = this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-14
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    相关资源
    最近更新 更多