【发布时间】:2017-11-21 05:15:56
【问题描述】:
我在我的 AngularJS 项目中使用 AngularFire。在下面的 HTML 中,您可以看到我正在将 quote 项传递给我的控制器中的 total_votes 函数。
<div ng-repeat="quote in quotes" ng-init="total_votes(quote)">
{{quote.name}}
</div>
这就是quotes 的来源
// get quotes
var ref = firebase.database().ref().child('quotes');
$scope.quotes_obj = $firebaseObject(ref);
$rootScope.quotes = $firebaseArray(ref);
这就是函数的样子
$scope.total_votes = function(itm) {
console.log(itm.votes)
console.log(itm.votes)
console.log(itm.votes[0])
console.log(itm.votes.length)
};
这是打印出来的
console.log(itm.votes)
{
"quote": "untitled",
"recorded_by": "-KzFkQYHWKwbAPjIekWz",
"votes": {
"-KzFkQYHWKwbAPjIekWz": "sad",
"-KzLT76T14doKgYbjRc1": "wow"
},
"who": "null",
"$id": "-KzKz7EyCSPkPl0YDvfa",
"$priority": null,
"$$hashKey": "object:15"
}
console.log(itm.votes)
{"-KzFkQYHWKwbAPjIekWz":"悲伤","-KzLT76T14doKgYbjRc1":"哇"}
console.log(itm.votes[0])
未定义
console.log(itm.votes.length)
未定义
如何迭代引用的投票?为什么长度未定义?为什么我无法通过 itm.votes[0] 之类的索引访问单个项目?
【问题讨论】:
标签: angularjs firebase firebase-realtime-database angularfire