我不知道如何访问从Firebase收到的数据,这里是对象:
0:Object
$$hashKey : "object:4"
$id : "-KPoOlGpoArhMjgPLms_"
$priority : null
$value : "{"name":"jone","phone":null,"company":null,"email":null,"workPhone":null,"address":null}"
__proto__ : Object
1 : Object
$$hashKey : "object:5"
$id : "-KPoOvSLgVFxa0ca7qaL"
$priority : null
$value : "{"name":"jone","email":"bdaa@ds.cokm","phone":null,"company":null,"workPhone":null,"address":null}"
__proto__ : Object
如何检索我需要的信息,例如:$ id和$ value是我需要的字段
这是我的控制器:
var db = fireBaseApp.instance.database().ref('contacts');
$scope.contacts = $firebaseArray(db);
$scope.contacts.$loaded().then(function (data) {
$scope.cont = data;
console.log($scope.cont);
});
所以我需要获取数据
答案 0 :(得分:1)
方法一:
var users = null;
function allContacts() {
users = $firebaseArray(db.child('contacts'));
}
return users;
}
或者也可以使用
function allContacts() {
var ref = firebase.database().ref('/contacts')
var obj = $firebaseObject(ref);
obj.$loaded().then(function() {
angular.forEach(obj, function(value, key) {
console.log(value, key);
});
});
}