【发布时间】:2018-07-13 19:09:15
【问题描述】:
这是我用来检查一个人是否已经投票的功能。我正在使用 Firebase 后端。
madeVote() {
let id = this.state.id
var userid = this.props.location.state.userid;
var idRef = database.ref('/voted/' + userid);
if (id == -1) {
alert("Please select a candidate")
} else {
var idQuery = idRef.child('voted');
//console.log(userid);
idQuery.once("value", function(snapshot) {
console.log("Value " + snapshot.val());
if (1) {
alert("You have already voted")
this.props.history.push('/thanks')
}
})
}
}
“this”在“this.props.history.push('/thanks')”行中为空。
我知道我需要绑定这个。但是我该怎么做呢?
【问题讨论】:
标签: reactjs firebase react-native this bind