如何获得一个firebaseArray对象的关键 [英] How to get the key of a firebaseArray object

查看:116
本文介绍了如何获得一个firebaseArray对象的关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取返回的firebaseArray记录的关键字,但没有运气。

我有一个服务运行以下内容来返回一个商店

  getStore:function(uid,id){
var ref = firebase.database()。ref('u /'+ UID + '/商店/' + ID + '/ I /');
//在数据加载后采取行动,使用$ loaded()promise
return $ firebaseArray(ref);

$ / code>

我通过调用服务来获取eeach记录

  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);
});



$ b $ p
$ b

在我的html中我可以访问数组中的各种属性

 < 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

解决方案

获取id只需调用项目上的$ id即可。

 < 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


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);
    });
}

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>

But I cannot seem to get the id for each store record from within the ng-repeat

解决方案

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>

See: https://github.com/firebase/angularfire/blob/master/docs/reference.md#firebasearray

这篇关于如何获得一个firebaseArray对象的关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆