【发布时间】:2018-03-29 05:25:09
【问题描述】:
我正在尝试使用Firebase 中的示例为非规范化数据库编写查询,我想要做的是:
获取当前用户下的表单列表 对于此列表中的每个项目,返回对每个项目的引用
这是我的代码:
getFormList():firebase.database.Reference {
// the old method
//return firebase.database().ref('/formsByID').orderByChild('userList').startAt(this.userId).endAt(this.userId);
var formRef = firebase.database().ref("/formsByID");
var userRef = firebase.database().ref("/userProfiles");
// this is our list of forms under the child node
var userFormRef = userRef.child(this.userId).child("formsList");
// when an item is added to our list of forms
userFormRef.on("child_added", function(snap) {
// snap.key is key of our form taken from forms list
//let formKey = snap.key(): string;
return formRef.child(snap.key);
});
}
问题是 typescript 期望从我的 getFormList 方法返回一个值,但只有在将新值添加到我的 userFormRef 时才会返回一个值 - 感谢任何帮助
【问题讨论】:
-
也许我需要把它分成 2 个函数——我会试试的
标签: angular typescript firebase firebase-realtime-database ionic3