本文介绍了如何通过Firebase中的按键读取项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的尝试,但它返回undefined,但我认为这不能没有键 .child(键)或这种性质的东西。

This is my attempt but it returns undefined but I've figured this can't be done without having the keys as .child(keys) or something of that nature.

var ref = new Firebase("https://users.firebaseio.com/");
ref.child("users").child(authData.uid).on("value", function(snapshot) {
  var users = snapshot.val();
  console.log("snap: " + snapshot.val());
  console.log("username: " + users.username);
  console.log("username: " + users.email);
});

这是我的firebase json文本。我想阅读电子邮件lastname和用户名,通过许多键,而不仅仅是每个键。

Here's my firebase json text. I want to read email lastname and username through many keys not just per key.

"users": {
  "6179eb29-9691-4828-be5a-28a94e84703b": {
    "-KLWoGzjymD0Sgvf5Rcs": {
      "email": "jaycarter@gmail.com",
      "lastname": "cater",
      "username": "jay"
    }
  },
  "6a210785-0a73-4c83-b3e1-d3828f9d8a3b": {
    "-KLqMiLTB71dTh7PrVpL": {
      "email": "k@gmail.com",
      "lastname": "john",
      "username": "smith"
    }
  }


推荐答案

taskref.onAuth(function(authData) {
      taskref
        .child("users")
        .child(authData.uid)
        .child("task")
        .orderByChild('date')
        .on('value', function(snapshot) {
          $scope.list = [];
          snapshot.forEach(function(child) {
            //  $scope.list = $scope.list.concat(child.val());
            $scope.list.splice(0, 0, child.val());
            console.log($scope.list);
          });

          $scope.taskKeys = function() {
            return Object.keys($scope.list);
          }

          $scope.complete = function(key) {
            taskref.child("users")
              .child(authData.uid)
              .child('task')
              .child(key)
              .set({
                status: true
              });
          }

        });

这篇关于如何通过Firebase中的按键读取项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 08:48