我正在制作一款首先让用户登录的安卓游戏,我想出了那个部分。该脚本在以后的游戏过程中根据用户ID将用户数据保存到用户。
现在我似乎无法弄清楚如何再次访问(级别)数据(我希望能够将其范围扩大)
app.factory("Auth", function($firebaseAuth) {
var FIREB = new Firebase("https://app.firebaseio.com");
return $firebaseAuth(FIREB);
});
app.controller('HomeScreen', function($scope, Auth, $firebaseArray, $firebaseObject) {
Auth.$onAuth(function(authData){
$scope.authData = authData;
});
var users = new Firebase("https://app.firebaseio.com/users/");
// create a synchronized array
$scope.users = $firebaseArray(users);
$scope.googlelogin = function() {
Auth.$authWithOAuthPopup("google").then(function(authData){
users.child($scope.authData.google.cachedUserProfile.id).set({
Username: $scope.authData.google.displayName,
Id: $scope.authData.google.cachedUserProfile.id,
Gender: $scope.authData.google.cachedUserProfile.gender,
level: "1"
});
}).catch(function(error){
});
}
$scope.googlelogout = function() {
Auth.$unauth();
}
$scope.changeLVL = function(authData, Auth) {
var user = new Firebase("https://app.firebaseio.com/users/" + $scope.authData.google.cachedUserProfile.id);
$scope.user = $firebaseArray(user);
$scope.level = $firebaseObject(user.child("level"));
var level = $firebaseObject(user.child("level"));
user.update({
level: level
});
}
});
有没有办法轻松定位关卡属性?当前我只能将它显示为数组而不是值。 (示例:显示“[]”而不是“2”或显示整个数组{“level”:“2”})
我的firebase数组设置如下,其中数字是帐户ID。
users
998995300163718
Email: "Name@email.com"
Gender: "male"
Id: "998995300163718"
Username: "name lastname"
level: "1"