以下是我的玩家JSON快照:
下面是在客户端选择玩家的代码:
$scope.history=[];
$scope.picked = [];
$scope.buy = function(player) {
//remove if already added locally
var index = $scope.history.indexOf(player);
var index2 = $scope.picked.indexOf(player.id);
if(index>=0 || index2>=0 ){
$scope.history.splice(index,1);
$scope.picked.splice(index2,1);
return;
}
//max 11 allowed
if($scope.history.length>=10 || $scope.picked.length>=10){
alert('max 10 players allowed');
return;
}
//to make sure moeny doesn't go below $10,000,000
if($scope.total<0){
alert('Oops! You have run out of cash');
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]<4 &&
$scope.total>0){
$scope.history.push(player);
$scope.picked.push(player.id);
}else{
alert('You can add only four players per position');
}
};
[
0: {Team: "AC Izzue", assists: 0, cost: "5m", goals: 0, id: 1, â¦}
1: {Team: "AC Izzue", assists: 0, cost: "5m", goals: 0, id: 2, â¦}
2: {Team: "AC Izzue", assists: 0, cost: "5m", goals: 0, id: 3, â¦}
3: {Team: "AC Izzue", assists: 0, cost: "5m", goals: 0, id: 4, â¦}
4: {Team: "AC Izzue", assists: 0, cost: "5m", goals: 0, id: 5, â¦}
5: {Team: "AC Izzue", assists: 0, cost: "5m", goals: 0, id: 6, â¦}
6: {Team: "AC Izzue", assists: 0, cost: "5m", goals: 0, id: 7, â¦}
7: {Team: "After Hours FC", assists: 0, cost: "5m", goals: 0, id: 16, â¦}
8: {Team: "Alaye FC", assists: 0, cost: "5m", goals: 0, id: 27, â¦}
9: {Team: "Alaye FC", assists: 0, cost: "5m", goals: 0, id 26}
]
每次我试着
push
set
错误:参考.推送失败:第一个参数在属性“”中包含无效的键($id)用户.UhIBZDBaLcTcesdRiJ9u7xYv9bd2.picked.0'。键必须是非空字符串,并且不能包含“.”、“\”、“$”、“/”、“[”或“]”
是否可以在firebase上的用户地址上成功地发布阵列,或者阵列是否必须更改?