1
我正在研究一個基於當地聯盟的幻想足球網絡應用程序。到目前爲止,使用火力AUTH在創建用戶時,就使用用戶的UID如下在我的火力點創造了相應的節點:如何在我的firebase數據庫中發佈我的數組?
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玩家選擇被張貼到了「周」節點,每個星期,選擇可以改變/ 更新 ?
感謝。與此相關的問題是,當用戶在下一週做出選擇時,更新功能將覆蓋前一週的選擇內容。但我希望能夠看到以前的選擇是什麼。我認爲數組不能使用set函數發佈。它似乎不能使用set。 –
是的,您可以使用set funcion發佈數組。它將創建或更新節點。我不明白你想做什麼。如果你想跟蹤前幾周,也許你需要重新設計你的模式。現在您將覆蓋本週的內容,所以如果您想添加新的一週,但保留之前的內容,您應該在一週內有多個節點。 – Joseba
我試過你的方法,但它不成功。我試着發佈隨機單詞,它的工作。我也嘗試使用$ scope.history [0]從數組中發佈特定的玩家,但它也沒有工作。 –