Firebase检索数据仅显示一个结果 [英] Firebase retrieve data shows only one result
问题描述
我正在尝试检索对象的数据,结果显示在控制台上,但页面上仅显示一个结果(最后一个结果).
I am trying to retrieve a data of objects and the result shows on the console but it only shows one result(the last result) on the page.
$http.get('/users').success(function(data) {
$scope.username = data; //assign data to username
console.log(data);
});
在我的Jade模板中,我有
And in my Jade template, i have
section(data-ng-controller='browse')
h4 hi
ul(data-ng-repeat='user in username')
li {{user}}
我想遍历这些数据
{
"google: xxxxxxxxxxxxx" : {
"name" : "ZZZ YYY",
"profile" : {
"briefProfile" : "Cost call",
"career" : "Web Developer",
"projects" : {
"-JjtSgiwkqFxTxMv0Gip" : "http://zipper.com"
}
},
"provider" : "google"
},
"google:xxxxxxxxxxx" : {
"name" : "SSS TTT",
"profile" : {
"briefProfile" : "Desired Intelligence",
"career" : "Consultant"
},
"provider" : "google"
}
}
谢谢.(我没有使用angularFire).
Thanks.(i'm not using angularFire).
推荐答案
如果您使用的是 $ http
服务,则说明您不是在使用Firebase.
If you're using the $http
service, then you're not using Firebase.
-
您正在重复
ul
,而不是li
.另外,{{user}}
将是整个用户对象,并且您会在页面上看到类似[Object object]的内容,而不是字符串.因此,调用{{user.name}}
.
You are repeating the
ul
instead of theli
. Also,{{user}}
will be the whole user object, and you will see something like [Object object] on your page instead of a string. So call{{user.name}}
.
ul
li(data-ng-repeat='user in users') {{user.name}}
Assuming that $http
is there by mistake, and you meant to use Firebase instead, you probably want to start by reviewing the Firebase Getting Started guide
// Get a reference to users
var ref = new Firebase('https://<YOUR-FIREBASE>.firebaseio.com/users');
// Attach an asynchronous callback to read the data at users ref
ref.on("value", function(snapshot) {
console.log(snapshot.val());
$scope.users = snapshot.val();
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
这篇关于Firebase检索数据仅显示一个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!