- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我不是 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 aconsole.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/
这个问题在这里已经有了答案: final keyword in method parameters [duplicate] (9 个回答) 关闭 8 年前。 在此示例中,声明 Object fina
我的目标:是通过我的函数更新字段获取选定值并使用函数输出值运行它。 问题:当我从列表中选择值时,它不会触发函数,也不会更新字段。 感谢您的帮助。 HTML 12 14 16 18 20 22 24
我有一本具有这种形式的字典: myDict = {'foo': bar, 'foobar baz': qux} 现在,我想拆分字典键中的空格,使其成为下一个键并获取值(重复)。 myDictRev1
vector a; vector b; int temp_holder; cout > temp_holder) a.push_back(temp_holder); cout > temp_h
Java 的开发过程中免不了与 Date 类型纠缠,准备总结一下项目经常使用的日期相关操作,JDK 版本 1.7,如果能够帮助大家节约那么几分钟起身活动一下,去泡杯咖啡,便是极好的,嘿嘿。当然,我
我正在使用 jquery ui 日期选择器来获取 fromDate 和 toDate 以下是from日期的代码 $("#from_date").datepicker({
我是一名优秀的程序员,十分优秀!