[Vuejs]-Firebase infinite loop insert my item on child_added/set

2👍

OK I’ve found a solution :

            //get the last item id and save it to next key
            var _nextKey = this.nextKey;
            usersRef.limitToLast(1).on('child_added', function (snapshot) {
                var lastKey = parseInt(snapshot.key());
                _nextKey = lastKey + 1;

            });
            this.nextKey = _nextKey;
            console.log('nextKey ' + this.nextKey);//test ok
            // save data to firebase
            usersRef.child(this.nextKey).set(jsonData, function (snap) {
                //console.log('add success');//test
                //Notification par Jquery
                var itemAdded = snap.val();
                $.notify(itemAdded.firstname + " " + itemAdded.name + " à été ajouté", "success", {position: "top right"});
            });

May it help someone!

Leave a comment