
在图像中,红色高亮显示的红色框显示了由firebase生成的密钥
我尝试做的是通过餐厅键在餐厅中添加菜单项,并将相同的菜单项添加到globalMenu。
因此,添加的菜单项将与restaurant中的副本一起出现在globalMenu中。
firebase所做的是通过复制restaurant键在数据库中添加一个新实体,而不是只将itemName添加到restaurant中。
如何解析建模库。
下面是我的代码:
//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]
};
// Get a key for a new Post.
var newItemKey = firebase.database().ref().child('globalMenu').push().key;
// Write the new item's data simultaneously in the globalMenu list and the restaurants's menu list.
var updates = {}, updatesRestaurant = {};
updates['/globalMenu/' + newItemKey] = menuItem;
updatesRestaurant['/restaurants/' + restaurantId + '/' + newItemKey] = menuItem;
firebase.database().ref().update(updatesRestaurant);
return firebase.database().ref().update(updates);
}
//Endhttps://stackoverflow.com/questions/38391195
复制相似问题