firebase - $firebaseArray $indexFor() not finding key when given value -
i have firebase:
users: { userid: { notifications: { notificationid: "notification" } } }
when given "notification", i'm trying find notificationid (which generated push() method) can delete it. according docs, $indexfor() method should me. here's code:
var ref = new firebase('https://url.firebaseio.com/'); $scope.dismissnotification = function(notification) { var notificationref = ref.child('users/' + $scope.currentuser.id + '/notifications'); var notifications = $firebasearray(notificationref); notifications.$loaded().then(function(data) { console.log(data); console.log(data.$indexfor(notification)); }).catch(function(error) { console.log('error: ' + error); }); };
the first log correct object notification string inside i'm looking for, second log returns -1, when want return notificationid associated it.
not sure you're trying accomplish, simplest way find key given value:
var notificationref = ref.child('users/' + $scope.currentuser.id + '/notifications'); var query = notificationref.orderbyvalue().equalto(notification); query.once('child_added', function(snapshot) { console.log(snapshot.key()); });
Comments
Post a Comment