【问题标题】:unable to bind $scope.profile to a view from controller to view无法将 $scope.profile 绑定到从控制器到视图的视图
【发布时间】:2016-06-15 21:29:59
【问题描述】:

theres what i've logged click on this link 好的,我现在使用 google 数据获取这些对象,我想深入了解用户名和 id 并能够绑定它。我怎么做?

d {$$conf: Object, $id: "google:107950469269631469408", $priority: null}
$$conf
:
Object
$id
:
"google:107950469269631469408"
$priority
:
null
-KK87pj5tW9EL8hL9To7
:
Object
id
:
"google:107950469269631469408"
name
:
"muzi ngobe"
__proto__
:
Object

如何实现对象中对象的获取?

var ref = new Firebase("https://tasksbylima.firebaseio.com/");
 $scope.profile = $firebaseObject(ref.child('users').child(authData.uid));
 console.log($scope.profile);

这就是我的 Firebase Json 树

{
  "users" : {
    "google:107950469269631469408" : {
      "-KK87pj5tW9EL8hL9To7" : {
        "id" : "google:107950469269631469408",
        "name" : "muzi ngobe"
      },

    }
  }
}





<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="list card">
            <div class="item item-divider">{{profile.name}}</div>
            <div class="item item-body">
                <form class="list">
                    <ion-checkbox>{{profile.name}}</ion-checkbox>
                </form>
            </div>
        </div>

【问题讨论】:

  • "loggin profile [object Object]" 发生这种情况是因为您在 console.log 中使用了字符串连接,因此为 $scope.profile 执行了 .toString 方法。要查看 $scope.profile 可以使用 debugger;console.log($scope.profile);
  • 我在删除 concationation 后得到一个 NaN 并且仍然没有绑定到视图上
  • 也去掉+号
  • 好的,我已经对帖子进行了更新,我现在可以看到对象但它在其他对象中,现在我如何去获取其中的用户名和 ID 的数据。看看上面的更新
  • 你能把它从复制粘贴格式化成普通格式吗?我可以看到名称字段,但用户名字段是什么?

标签: angularjs firebase firebase-realtime-database


【解决方案1】:

您可以通过访问对象的第一个属性来打开答案对象:

var ref = new Firebase("https://tasksbylima.firebaseio.com/");
var response = $firebaseObject(ref.child('users').child(authData.uid));
var users = response[Object.keys(response)[0]];
var google = users[Object.keys(users)[0]];
var key = google[Object.keys(google)[0]];
console.log(key);

【讨论】:

  • console.log(key.name) 而不是$scope.profile.name = key.name;
  • 那也是未定义的
  • 我无法查看此链接访问被拒绝
  • 对不起.. 屏幕截图出了点问题。这是一个新的:i.prntscr.com/a6eb4348d9db4c1cb4779929ff4f1d25.png
  • 我仍然无法访问您的屏幕截图
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多