【发布时间】:2017-10-15 05:41:39
【问题描述】:
我正在开发一个基于本地联赛的梦幻足球网络应用。到目前为止,当使用 firebase auth 创建用户时,在我的 firebase 中使用用户 uid 创建了一个相应的节点,如下所示:
users:{
user UID: {
email:
teamname:
fullname:
week:
}
}
我有一个名为 $scope.history 的空数组和每个选定玩家的购买函数:
$scope.history = [];
$scope.buy = function(player) {
$scope.total = 50000000;
//remove if already added
var index = $scope.history.indexOf(player);
if(index>=0){
$scope.history.splice(index,1);
return;
}
//max 6 allowed
if($scope.history.length>=6){
alert('max 6 allowed');
return;
}
var selected = $scope.history.reduce(function(a,b){
a[b.position] = (a[b.position] || 0) + 1;
return a;
}, {}) || {};
if(!selected[player.position] || selected[player.position]<2){
$scope.history.push(player);
}else{
alert('You can add only two players per position');
}
};
$scope.getTotal = function(){
return $scope.history.reduce(function(tot, p){
tot = tot - p.price;
return tot;
}, $scope.total);
};
我的问题
我的问题是当用户选择 6 位玩家数组(每个玩家都是一个 JSON 对象)时,如何将该数组发布到相应用户的用户 UID 父节点下的“周”子节点?
我尝试过这样做,但没有成功:
$scope.saveTeam = function(){
var ref2 = firebase.database().ref("users/" + auth.uid + "/week");
ref2.set($scope.history);
};
有没有办法将每个用户的 6 名玩家选择发布到“周”节点,以便每周可以更改/更新选择?
【问题讨论】:
标签: javascript angularjs firebase web-applications firebase-realtime-database