2015-12-30 54 views
5

我试图从我的HTML中使用AngularJS从Firebase获取数据。它工作正常,但当我到达子节点时,它以意想不到的形式显示数据。 请找到图片的细节:

我已在火力地堡进口

JSON文件:

My Json File

火力数据表示:

FireBase Data

数据在HTML返回:

enter image description here

预期的数据为

enter image description here

在我的控制,我想从火力点获得的数据为:

$scope.locService = $rootScope.service; 
    var serviceRef = new Firebase(FIREBASE_URL+"ABC/location/"+$rootScope.location+"/services/"+$rootScope.service+"/"+$rootScope.serviceDetail+""); 
    $scope.details = $firebaseArray(serviceRef); 

$ rootScope值正常,因为它正在返回数据(这不是预期的格式,即使用$ id,$ value,$ priority)。

在我的HTML:

<div class="content has-header"> 
     <h2>{{details[0]}}</h2> 
</div> 

请帮助我。在此先感谢您的建议

+1

在文档中描述了那些意外的属性。所以他们预计,事实上:https://www.firebase.com/docs/web/libraries/angular/guide/synchronized-arrays.html –

回答

0

AngularFire从一系列Firebase DataSnapshots创建一个同步阵列。快照包含数据以及其他有用的数据,如keypriority。 AngularFire使用$前缀来包含阵列中每个项目的这些数据。

对于您的情况,您尝试同步一系列基元,为了让AngularFire为您提供像key这样的重要信息,它包含对象中的基元,并通过$value访问原始值属性。

Check out the AngularFire docs on meta fields for more information.

如果不希望这种行为,那么你就必须要么使用$firebaseObject()或者去上一级的JSON树。你可能想要使用$firebaseObject()

$scope.locService = $rootScope.service; 
var serviceRef = new Firebase(FIREBASE_URL+"ABC/location/"+$rootScope.location+"/services/"+$rootScope.service+"/"+$rootScope.serviceDetail+""); 
$scope.details = $firebaseObject(serviceRef);