调用Superagent-React回调中的函数



我想在请求结束时(当我得到响应时(用Superagent调用一个函数。

request.post('/TextUpload')
.send({title:this.state.title1})
.end( function(res){
console.log(res);
this.myFunction();
})

但我得到了一个错误:这是null或未定义的。

MyFunction((是在构造函数中声明和绑定的。我不能直接在回调中写入函数的代码,因为我执行this.props.refresh(true);(它向父级发送数据(

我得到错误:这是null或未定义。?

这应该有效。使用箭头函数获取词法范围绑定

.end((res)=>{
console.log(res);
this.myFunction();
})

最新更新