【发布时间】:2019-03-22 01:30:22
【问题描述】:
我正在尝试根据子值 matchID 从我的 Firebase 实时数据库中查询数据。
下面是我的 matchPredictions 表的 JSON 导出,其中只有一个条目。
{
"-LP0aVMsmqfdHj7yfPnK" : {
"matchID" : "-LP0LKl_nR4VQf6Gxwz8",
"matchKickoff" : "2019-01-12T12:00",
"teamAName" : "Germany",
"teamAScore" : "2",
"teamBName" : "Denmark",
"teamBScore" : "3",
"userId" : "RZVbxcIB1SWxj0ohgJDqkEU9ia13"
}
}
我有以下被调用的函数..
export const fetchPredictionsForCompletedMatch = (match, token) => {
console.log("Match is " +match);
console.log("matchPredictionsFBRef is " + matchPredictionsFBRef);
const retrievePreds = matchPredictionsFBRef.orderByChild("matchID").equalTo(match).on("value",
function(snapshot){
console.log("Snapshot here is "+ snapshot);
});
return dispatch => {
retrievePreds.then(
response => dispatch(addMatchResultSuccess(match))
)
.catch(
err => dispatch(addMatchResultFail(err))
)
}
}
match 的值是预期的 -LP0LKl_nR4VQf6Gxwz8 并且 matchPredictionsFBRef 是 https://projectOne.firebaseio.com/matchPredictions, 这是我要查询的表。
运行时会抛出错误“错误是 TypeError:retrievePreds.then 不是函数”,并且快照不会打印到控制台。
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: reactjs firebase-realtime-database react-redux