如何打印从Firebase返回的对象的密钥? 具体来说,我如何打印团队名称?例如。 “很棒的团队”
控制器:
app.controller('TeamsController', ['$scope', '$firebaseObject','ENV',
function($scope, $firebaseObject, ENV){
var app_id = ENV.FIREBASE_APP_ID;
var ref = new Firebase("https://"+app_id+".firebaseio.com/teams");
$scope.teams = $firebaseObject(ref);
}
]);
返回的数据是:
{"$id":"teams","$priority":null,"Awesome Team":{"created":"11-11-1111","size":3},"Team 1":{"created":"26-11-1111","size":4}}
然后在视图中:
<tr ng-repeat="team in teams">
<td>{{$id}}</td>
<td>{{team.created}}</td>
<td>{{team.size}}</td>
<td><button ng-click="">X</button></td>
</tr>
答案 0 :(得分:1)
使用ng-repeat对Firebase引用进行迭代应使用$firebaseArray
而不是$firebaseObject
进行。使用$firebaseArray
时,每个孩子都有一个包含对象密钥的$id
属性。
<tr ng-repeat="team in teams">
<td>{{team.$id}}</td>
<td>{{team.created}}</td>
<td>{{team.size}}</td>
<td><button ng-click="">X</button></td>
</tr>