Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

Auto increment a value in firebase with javascript

Hello I'm working on some firebase project and i can save my datas via javascript into firebase database. But i couldn't figure it out to auto increment child value (my child value is duyuru, you can see the details in the below) of my database. I'm sharing my code in below can you give me hints to solve this issue.

  <script>

      // Initialize Firebase
      var config = {
        apiKey: "sample1",
        authDomain: "sample2",
        databaseURL: "sample3",
        storageBucket: "sample4",
      };


      firebase.initializeApp(config);
      var database = firebase.database();

     firebase.initializeApp(config);
  var database = firebase.database();

  function writeUserData(userId, name, email, imageUrl) {
  var kategori1 =  document.getElementById("kategori").value;
  var duyuru1 = document.getElementById("duyuru").value;
  var name1 = document.getElementById("name").value;
  var email1 = document.getElementById("email").value;
  var imageUrl1 = document.getElementById("imageUrl").value;





  firebase.database().ref(kategori1 +"/" + duyuru1).set({
    username: name1,
    email: email1,
    profile_picture : imageUrl1
  });
}

    </script>

and the out is like this

{
    "duyuru1": {
        "email": "kjfdlkl",
        "profile_picture": "dsfsd",
        "username": "meraha"
    }
}

I want to output data like;

{
    "duyuru1": {
        "email": "kjfdlkl",
        "profile_picture": "dsfsd",
        "username": "meraha"
    },

    "duyuru2": {
        "email": "kjfdlkl",
        "profile_picture": "dsfsd",
        "username": "meraha"
    }
}

duyuru (child value) section should be auto increment, That's what i wanted for. Thank you for your answers

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...