我有一个按钮监听器,它通过一个超级代理传递一些登录信息,我得到一个返回的令牌。现在我想将我的状态属性更新为收到的令牌,我得到了正确的。但我的 this.state.token 似乎没有更新。
这是我的代码:
_btnLoginListener: function () {
var that = this;
superAgentRequest
.post(URL + TOKENS_KEY)
.type('json')
.send({
email: this.state.usernameOrEmail,
password: this.state.password
})
.end(function ( err, res ) {
// Calling the end function will send the superAgentRequest
if (res.status == 200) {
/*var token = JSON.parse(res.text).token; // working*/
/*ToastAndroid.show("POST Response -> " + token, ToastAndroid.SHORT)*/
that.setState({
token: JSON.parse(res.text)
})
navigator.replace({
id: 'MainController',
name: 'MainController',
});
} else {
notifyMessage ("Please check credentials again!")
}
})
}
notifyMessage (that.state.token)
},