在从表单发出请求后,我想用表单响应更新ui。所以在成功回调之后我将响应设置为道具。 handleNewLift
。但是在那之后我会遇到错误。
lift_form.self-ed34db8 ... .js?body = 1:28未捕获的TypeError:无法读取 属性'handleNewLift'未定义
LiftForm.js.jsx
var LiftForm = React.createClass({
handleSubmit: function (e) {
e.preventDefault();
$.ajax({
url: "/lifts",
type: "POST",
data: {lift: this.state},
success: function (data) {
this.props.handleNewLift(data);
this.setState = this.getInitialState();
}
});
}
Lifts.js.jsx
var Lifts = React.createClass({
getInitialState: function () {
return {
lifts: this.props.data
}
},
getDefaultProps: function () {
return {
lifts: []
}
},
addLift: function (lift) {
lifts = this.state.lifts.slice();
lifts.push(lift);
this.setState.lifts = lifts;
},
render: function () {
return (
<div className="Lifts">
<h1 className="title">Lifts</h1>
<LiftForm handleNewLift={this.addLift}/>
</div>
)
}
});
在学习反应时,我无法弄清楚问题是什么。