如何获取 firebaseArray 对象的键 [英] How to get the key of a firebaseArray object
本文介绍了如何获取 firebaseArray 对象的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取返回的 firebaseArray 记录的密钥,但我没有运气.
I am trying to get the key for a returned firebaseArray record but am having no luck.
我有一个服务,它运行以下命令来返回一个商店
I have aservice that runs the following to return a store
getStore: function(uid, id){
var ref = firebase.database().ref('u/'+uid+'/stores/'+id+'/i/');
// to take an action after the data loads, use the $loaded() promise
return $firebaseArray(ref);
}
我使用以下方法通过调用服务来获取每条记录
I use the following to get eeach record by calling the service
for(var i = 0; i < $scope.storesList.length; i++){
var storeInfo = Stores.getStore($rootScope.user['uid'], $scope.storesList[i]['$id']);
storeInfo.$loaded().then(function(data){
$scope.stores.push(data);
console.log($scope.stores);
});
}
在我的 html 中,我可以访问数组中的各种属性
In my html I can access various properties within the array
<li ng-repeat="store in stores">
<span class="store-address">{{store.$getRecord('name').$value}}</span>
<span class="store-address">{{store.$getRecord('address1').$value}}</span>
</li>
但我似乎无法从 ng-repeat 中获取每个商店记录的 id
But I cannot seem to get the id for each store record from within the ng-repeat
推荐答案
要获取 id,只需调用项目上的 $id.
To get the id simply call the $id on the item.
<li ng-repeat="store in stores">
<span class="store-address">{{store.$getRecord('name').$value}}</span>
<span class="store-address">{{store.$getRecord('address1').$value}}</span>
<span class="store-address">{{store.$id}}</span>
</li>
参见:https://github.com/firebase/angularfire/blob/master/docs/reference.md#firebasearray
这篇关于如何获取 firebaseArray 对象的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文