我正在使用Firebase和Ionic Framework。我正在使用以下代码获取记录:
var ref = new Firebase("https://blazing-fire-2739.firebaseio.com/new");
var arr=[];
// Retrieve new posts as they are added to our database
ref.on("child_added", function(snapshot, prevChildKey) {
var newPost = snapshot.val();
//console.log(newPost);
arr.push(newPost.data);
//console.log("Author: " + newPost.data.email);
//console.log("Title: " + newPost.date_of_birth);
// console.log("Previous Post ID: " + prevChildKey);
});
$scope.datas = arr;
console.log($scope.datas)
它将打印如下内容:
[]
0 =>Object { email="kk@gmail.com", firstname="karan", lastname="sofat", more...}
1=>Object { email="jj@gmail.cpm", firstname="jyotsna", lastname="kaushal", more...}
我正在查看文件中显示:
<div class="item item-button-right" ng-repeat = "x in datas" >
{{x.email}}
</div>
这不会打印任何内容
答案 0 :(得分:0)
你的数组数据不是正确的JSON数组格式。像这样,
function MyCtrl($scope) {
$scope.datas = [{
email: "kk@gmail.com",
firstname: "karan",
lastname: "sofat"
}, {
email: "jj@gmail.cpm",
firstname: "jyotsna",
lastname: "kaushal"
}];
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<div ng-app ng-controller="MyCtrl">
<div class="item item-button-right" ng-repeat="x in datas">
{{x.email}}
</div>
</div>
答案 1 :(得分:-1)
正如jQuery API所说:“使用GET HTTP请求从服务器加载JSON编码的数据。”
因此您无法使用该功能加载本地文件。但是当你浏览网页时,你会看到在javascript中加载文件系统中的文件非常困难,如下面的主题所示:Local file access with javascript