i create foreach loop. can access data firebase loop , can change variable. can not save these changes on firebase. how can save these changes? here's code:
var posts = $firebasearray(ref); posts.$loaded().then(function(item){ item.foreach(function(childsnapshot){ var num = childsnapshot.point-1; childsnapshot.lastpoint = num; }); });
you're using angularfire framework, builds ui bindings on top of firebase's regular javascript sdk. should using things you're binding angular ui elements. else, you're better off using firebase's regular javascript sdk.
if understand requirement correctly, you're trying loop on child nodes in database location once , modify property. if so:
ref.once('value', function(snapshot) { snapshot.foreach(function(childsnapshot) { var child = childsnapshot.val(); childsnapshot.ref().update({ lastpoint: child.point - 1 }); }); }); the relevant sections of firebase documentation on reading data once , updating data.
since angularfire built on top of firebase's javascript sdk, work together. if elsewhere bind posts scope ($scope.posts = $firebasearray(ref)), updated automatically when update last point above snippet.
Comments
Post a Comment