Javascript 如何在整个JSON树中更新firebase数据库上的节点?
我的web应用程序基于足球联赛。我有一个Javascript对象数组。每个玩家都是阵列中的一个对象:Javascript 如何在整个JSON树中更新firebase数据库上的节点?,javascript,angularjs,firebase,web-applications,firebase-realtime-database,Javascript,Angularjs,Firebase,Web Applications,Firebase Realtime Database,我的web应用程序基于足球联赛。我有一个Javascript对象数组。每个玩家都是阵列中的一个对象: $scope.players = [ {name : "Yasin 'YB' Amusan", Team : "Industry", price: 8000000, position: 'forward', image: src='http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png'
$scope.players = [
{name : "Yasin 'YB' Amusan", Team : "Industry", price: 8000000, position: 'forward', image: src='http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png'},
{name : "Hassan 'Hasi' Akinyera", Team : "Industry", price: 5000000, position: 'defender', image: src='http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png'},
{name : "Femi 'Fabio' Awoniyi", Team : "Industry", price: 9000000, position: 'defender',image: src='http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png'},
{name : "Deji 'Dej' Awoniyi", Team : "Industry", price: 7000000, position: 'forward',image: src='http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png'},
{name : "Koye 'K10' Kekere-Ekun", Team : "Industry", price: 9000000, position:'midfielder', image: src='http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png'},
{name : "Teni 'Teezee' Zacchaeus", Team : "Industry", price: 6000000, position:'hybrid', image: src='http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png'},
{name : "Bolaji 'Boj' Odojukan", Team : "Industry", price: 7000000, position:'forward', image: src='http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png'}
];
然而,当玩家数量增加到47人左右时,我决定使用firebase作为后端。因此,我制作了一个玩家的JSON文件,并将其导入firebase数据库:
{
"players" : [
{"name" : "Yasin 'YB' Amusan",
"Team" : "Industry",
"price": 8000000,
"position": "forward",
"image":"http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png",
"goals": 0,
"assists" : 0,
"Y" : 0,
"R" : 0},
{"name" : "Hassan 'Hasi' Akinyera",
"Team" : "Industry",
"price": 5000000,
"position": "defender",
"image":"http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png",
"goals": 0,
"assists" : 0,
"Y" : 0,
"R" : 0},
{"name" : "Femi 'Fabio' Awoniyi",
"Team" : "Industry",
"price": 9000000,
"position": "defender",
"image":"http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png",
"goals": 0,
"assists" : 0,
"Y" : 0,
"R" : 0},
{"name" : "Deji 'Dej' Awoniyi",
"Team" : "Industry",
"price": 7000000,
"position": "forward",
"image":"http://res.cloudinary.com/deji/image/upload/v1489787662/blank_photo_mqvivv.png",
"goals": 0,
"assists" : 0,
"Y" : 0,
"R" : 0}
....etc
]
}
将列出玩家,供用户使用:
var ref = firebase.database().ref().child('players');
$scope.players = $firebaseArray(ref);
console.log ($scope.players);
当每个用户挑选他们想要的玩家时,它会被发布到名为“gameweek 1”的“用户”节点下的子节点,并根据每个玩家的性能/统计数据分配相应的分数
我的问题
我的问题是如何更新数据库中“玩家”节点中的玩家统计信息,使其在“用户”节点中每个用户选择下的“游戏周”子节点中更新。由于要同时更新多个路径的路径,您正在查找firebase.database().ref().update(),可在此处找到()@user7814783我想更像是在firebase控制台中手动更新它。这是不可能的吗?没有手动是不可能的,你必须随时随地改变它,否则你可以考虑使用云函数来触发一个函数,当数据库中的一个节点被改变并在你想要的节点中应用更改时。