Arrays 在my cloud函数中运行角度JS映射函数
在我的angular JS web应用程序中,以下功能运行良好:Arrays 在my cloud函数中运行角度JS映射函数,arrays,firebase,firebase-realtime-database,google-cloud-functions,Arrays,Firebase,Firebase Realtime Database,Google Cloud Functions,在我的angular JS web应用程序中,以下功能运行良好: $firebaseArray(orderedPlayers) .$loaded(function(loadedPlayers) { var normalizedPlayers = loadedPlayers.reduce(function(acc, next) { acc[next.id] = next; return acc; }, {}); var sel
$firebaseArray(orderedPlayers)
.$loaded(function(loadedPlayers) {
var normalizedPlayers = loadedPlayers.reduce(function(acc, next) { acc[next.id] = next; return acc; }, {});
var selectedPlayers = $scope.selection.map(function(num){
return normalizedPlayers[num];
});
$scope.players = selectedPlayers;
我尝试将he函数转换为我的云函数,如下所示:
snapshot.forEach(function(userSnapshot) {
var users = userSnapshot.val();
var selection = users.selection;
admin.database().ref("Player").child("playerweek8").once('value')
.then(function(dataSnapshot) {
let yourArray = [];
var orderedPlayers = dataSnapshot.val();
yourArray.push(orderedPlayers);
var normalizedPlayers = yourArray.reduce(function(acc, next) { acc[next.id] = next; return acc; }, {});
var selectedPlayers = selection.map(function(num){
return normalizedPlayers[num];
});
var players = selectedPlayers;
但是,my cloud函数返回错误:“selection.map不是函数”
有没有办法解决这个问题,让云功能像在web应用程序中一样运行
下面是我的数据库json的一个片段,它应该更能理解上述内容:
{
"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}],
Users: [{
"1YrpX2W2xnMPoy4YGpZcOE0xJ5g2" : {
"email" : "muyiwaawoniyi@hotmail.com",
"fullname" : "Muyiz",
"selection" : [ 1, 2, 3, 4, 5, 6 ],
"teamname" : "Donawon",
"total" : 12,
"userName" : "muyiwaawoniyi@hotmail.com",
"week1" : 0,
"week10" : 0,
"week11" : 0,
"week12" : 0,
"week2" : 0,
"week3" : 0,
"week4" : 0,
"week5" : 0,
"week6" : 12,
"week7" : 0,
"week8" : 0,
"week9" : 0
},
"6K9rQiZQ3jaV38WWtDbNwxhqIwc2" : {
"email" : "dami.etomi@gmail.com",
"fullname" : "Dami Etomi",
"selection" : 0,
"teamname" : "Bayern Neverlosin'",
"total" : 0,
"userName" : "dami.etomi@gmail.com",
"week1" : 0,
"week10" : 0,
"week11" : 0,
"week12" : 0,
"week2" : 0,
"week3" : 0,
"week4" : 0,
"week5" : 0,
"week6" : 0,
"week7" : 0,
"week8" : 0,
"week9" : 0
}
]
代码中的
选项是什么?这里没有显示。@DougStevenson嘿。我编辑了这个问题来回答这个问题,当你检查它的内容时,什么是用户
?听起来它的selection
属性不像你想象的那样。@DougStevenson我对它工作原理的理解是users
是一个数组,selection
是user
数组中每个用户都拥有的一个键。我试图在questionconsole末尾的数据库快照中反映这一点。在试图找出变量中的内容时,log()是您的朋友。我只能猜到里面有什么。你可以肯定地知道。