我正在尝试检索对象的数据,结果显示在控制台上,但页面上仅显示一个结果(最后一个结果)。
$http.get('/users').success(function(data) {
$scope.username = data; //assign data to username
console.log(data);
});
在我的Jade模板中,
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)。
如果您使用的是$http
服务,则说明您不是在使用Firebase。
您正在重复ul
而不是li
。另外,{{user}}
将是整个用户对象,并且您会在页面上看到类似[Object object]的内容,而不是字符串。所以打电话{{user.name}}
。
ul
li(data-ng-repeat='user in users') {{user.name}}
假设$http
那里存在错误,并且您打算改用Firebase,则可能需要先阅读《 Firebase入门指南》。
// 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);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句