gpt4 book ai didi

javascript - 如何从angularJS中的$firebaseArray获取值和$id

转载 作者:行者123 更新时间:2023-11-30 15:39:46 25 4
gpt4 key购买 nike

您好,我不是 firebase 的专家,只是刚开始使用它。在搜索了很多地方后,我找不到解决问题的方法。 My firebase database structure is as follow:我想检索特定配置文件的数据以及由 firebase 和生成的唯一 $id。

  $scope.login = function(users)
{
firebase.auth().signInWithEmailAndPassword(users.email, users.password)
.then(function(result)
{
var ref = firebase.database().ref("/profiles");
var examination = $firebaseArray(ref.orderByChild('uid').equalTo(result.uid));
console.log(examination);

我得到的结果是 like this任何人都可以在这方面帮助我,即如何从结果中获取值(value)。提前致谢。

最佳答案

如果您想检索数据并将其记录在您的代码中,请不要使用 AngularFire 并坚持使用 JavaScript SDK:

$scope.login = function(users) {
firebase.auth().signInWithEmailAndPassword(users.email, users.password)
.then(function(result) {
var ref = firebase.database().ref("/profiles");
var examination = ref.orderByChild('uid').equalTo(result.uid);
examination.on('value', function(snapshot) {
console.log(snapshot.val());
});

您会注意到我添加了 on('value',这是您告诉 Firebase SDK 开始从数据库加载数据的方式。Firebase documentation for web developers 和我强烈建议您从头到尾阅读那篇文章。在那里花费几个小时,您会遇到比想象中更多的问题。

如果您更喜欢坚持使用 AngularFire,那么您应该停止使用 console.log 检查加载状态。从 AngularFire quickstart 开始:

... $scope.data is going to be populated from the remote server. This is an asynchronous call, so it will take some time before the data becomes available in the controller. While it might be tempting to put a console.log on the next line to read the results, the data won't be downloaded yet, so the object will appear to be empty.

相反,您可以直接在 HTML 模板中直接显示数据:

The easiest way to log the data is to print it within the view using Angular's json filter. AngularFire tells the Angular compiler when it has finished loading the data, so there is no need to worry about when it be available.

<pre>{{ data | json }}</pre>

最后一个片段来自 AngularFire 指南中的 handling asynchronous operations

关于javascript - 如何从angularJS中的$firebaseArray获取值和$id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40996305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com