javascript - How to get push id uniquely -
i'm building forum, , i'm in step of views. have (simplified) code:
//setting views //adding them.. $scope.views = $firebaseobject(refservice.ref().child("topics")) refservice.ref().child("topics").once("value", function(snapshot) { snapshot.foreach(function(childsnapshot) { var key = childsnapshot.key(); var childdata = childsnapshot.val(); if(childdata.datecreated == $stateparams.date && childdata.email == $stateparams.email){ refservice.ref().child("topics").child(childdata.pushkey).child("views").child(currentauth.uid).set({ views : true }) } }) }) //viewing them $scope.viewableview = $firebaseobject(refservice.ref().child("topics"))
as can see adding views pretty easy job. , did correctly. problem displaying number of views, , have using angularfire's $firebaseobject
, or $firebasearray
... here structure in database:
{ "topics" : { "-kg9rdnlzksjdilfaxwh" : { "avatar" : "http://cs624223.vk.me/v624223037/2b1bb/grtkddkmxiw.jpg", "datecreated" : 1461544873669, "email" : "abogale2@gmail.com", "title" : "check", "uid" : "3caf2136-7a2d-4ae4-a4a9-119f2b08133c", "username" : "bruhbrhu", "value" : "check", "views" : { "3caf2136-7a2d-4ae4-a4a9-119f2b08133c" : { "views" : true } }, "pushkey" : "-kg9rdnlzksjdilfaxwh" } }, "userauthinfo" : { "3caf2136-7a2d-4ae4-a4a9-119f2b08133c" : { "bronzebadge" : 0, "description" : "just wierd 15 year old coder...", "email" : "abogale2@gmail.com", "goldbadge" : 0, "image" : "http://cs624223.vk.me/v624223037/2b1bb/grtkddkmxiw.jpg", "moderator" : false, "password" : "kfucq1yedoi1gengp6i1kq==", "platinumbadge" : 0, "silverbadge" : 0, "uid" : "3caf2136-7a2d-4ae4-a4a9-119f2b08133c", "username" : "bruhbrhu" } } }
as can see used push()
, topic.. concern how view topics! please help! can't think of "algorithm" it!
mind you, of topics have unique id's. have specific id user in.
this worked me:
refservice.ref().child("topics").once("value", function(snapshot) { snapshot.foreach(function(childsnapshot) { var key = childsnapshot.key(); var childdata = childsnapshot.val(); if(childdata.datecreated == $stateparams.date && childdata.email == $stateparams.email){ refservice.ref().child("topics").child(childdata.pushkey).child("views").on("value", function(snapshot){ console.log(snapshot.numchildren()) $scope.countviews = snapshot.numchildren(); }) } }) })
i dont know how somehow $scope.countviews, became 3 way binded html, shows!
Comments
Post a Comment