
这里是我的代码
//1. Add menu items to the globalMenu and to restaurant, and the restaurantId of the restaurant adding menu.
this.writeNewMenuItem = function(itemName, restaurantId) {
// A post entry.
var menuItem = {
itemName: [itemName]
};
var ref = firebase.database().ref();
// Get a key for a new Post.
var newItem = ref
.child('globalMenu')
.push(menuItem);
ref
.child('restaurants')
.child(restaurantId)
//.child(newItem.key)
.update(menuItem);
}发布于 2017-08-15 16:19:27
您应该尽量避免在Firebase数据库中使用“数组”,因为:
...对于分布式数据,它们是不可靠的,因为它们缺乏唯一的、永久的方式来访问每条记录。
https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html
关于您的第三个问题:以这种方式查询数据库是不可能的,您需要接收所有子节点的完整列表,并在客户端进行过滤。我建议阅读结构化数据的最佳实践:https://firebase.google.com/docs/database/admin/structure-data
https://stackoverflow.com/questions/38396123
复制相似问题