getDOMNode不是函数

getDOMNode is not a function

本文关键字:函数 getDOMNode      更新时间:2023-09-26

我正在使用ReactJS和Bootstrap.js创建一个模态。我的App.js是:

var App = React.createClass({
  showModal: function() {
    $(this.refs.modal.getDOMNode()).modal();
  },
  render : function(){
    return (
      <div>
        <button className="btn btn-default" onClick={this.showModal}>
            Show Modal
        </button>
        <Modal ref="modal" />
      </div>
    );
  }
});
ReactDom.render(<App/>, document.getElementById('app'))

当我点击show modal控制台时,会出现getDOMNode不是函数的错误。

PS:请不要建议使用React Bootstrap我不想使用普通的Bootstrap.js.来创建这个

提前感谢

更改您的线路

$(this.refs.modal.getDOMNode()).modal();

$(ReactDOM.findDOMNode(this.refs.modal)).modal();