samedi 23 novembre 2019

Uncaught ReferenceError: fn_get_data_oneid is not defined at HTMLDivElement.onclick

I am a newbie to firebase and Javascript

I am trying to have a onclick function which should directs to other javascript function where i change the textbox value.(For modification)

But there is an error

error -> Uncaught ReferenceError: fn_get_data_oneid is not defined at HTMLDivElement.onclick

enter image description here

Please tell me the solution..

   
 var auth;
 var db; 
 var userInfo; 
 var userInfo;
 var name;
 var selectedKey;

  $(document).ready(function() {
    auth = firebase.auth();
    db = firebase.database();
    userInfo = firebase.auth().currentUser;

   userSessionCheck();

   diaryList();


   function diaryList(){ 
     var diary_Ref = db.ref('Diary/');

     diary_Ref.on('child_added', on_diary_list);
   }


   function on_diary_list(data){

       var key = data.key;
       var Data = data.val();
       var contents = Data.contents;
       var title = Data.title;
       var name = Data.name;

       console.log(data.key);


    if(name == userInfo.displayName){
      var html =
      "<div id='" + key + "' onclick=\"fn_get_data_oneid(this.id);\" >" +
      '<div class="user_diary" style="float:left">' +
        '<ion-icon name="create" style="vertical-align: middle; margin-left: 10px;"></ion-icon>' +
        '<span style="font-weight: bold; font-size: 17px;">' + name +'</span>' +
        '<span style="float:right; margin-right:10px;" id="del_diary" onclick="fn_delete_date('+key+');">delete</span>' +
        '<span style="float:right; margin-right:10px;" id="update_diary">update</span>' +
        '</div>' +
      '<div class="result_form" style="width: 70%; overflow: hidden; display: block; margin-bottom:30px; float: left">' +
        '<div class="left" id="title">' +
          '<h4 style="font-weight: bold; margin: 10px;">'+
           '<ion-icon name="list"></ion-icon>' + title +
          '</h4>' +
         '</div>' +
        '<div class="left" style=" margin: 10px;">' +
         '<span style="margin: 10px 10px 10px 10px;  float: left; width: 95%; font-size: 15px; display: inline-block; padding-left:7px;">' +
          contents +
         '</span>' +
        '</div>' +
      '</div>' +
      '</div>';

      $('#diary_result').append(html);

    } else{
      var html =
      '<div class="user_diary" style="background: #777; float: right">' +
        '<ion-icon name="create" style="vertical-align: middle; margin-left: 10px;"></ion-icon>' +
        '<span style="font-weight: bold; font-size: 17px;">' + name +'</span>' +
       '</div>' +
      '<div class="result_form" style="width: 70%; overflow: hidden; display: block; margin-bottom:30px; float: right">' +
        '<div class="left">' +
          '<h4 style="font-weight: bold; margin: 10px;">'+
           '<ion-icon name="list"></ion-icon>' + title +
          '</h4>' +
         '</div>' +
        '<div class="left" style=" margin: 10px;">' +
         '<span style="margin: 10px 10px 10px 10px;  float: left; width: 95%; font-size: 15px; display: inline-block; padding-left:7px;">' +
          contents +
         '</span>' +
        '</div>' +
          '</div>' ;

      $('#diary_result').append(html);
    }



 }


   function fn_get_data_oneid(key){
   
     var diary_Ref = db.ref('Diary/' + key);
     diary_Ref.once('value').then(function(snapshot){
       $('#d_contents').val(snapshot.val().contents);
       $('#d_subject').val(snapshot.val().title);
     });
   }

   function fn_delete_date(key) {
   
     if (!confirm('delete?')) {
     return;
   }

   var diary_ref= db.ref('Diary/' + key);
   diary_ref.remove();

  };

   function save_data(){
     var diary_Ref = db.ref('Diary/');
     var contents = $('#d_contents').val();
  //   var name = displayName;
     var title = $("#d_subject").val();
     if (contents === '' || contents===' ' || title === '' || title === ' '){
       alert('title or contents == null');
       return;
     }


     if(selectedKey) {
       diary_Ref = db.ref('Diary/' + selectedKey);
       diary_Ref.update({
         'contents' : contents,
         'name' : name,
         'title': title
       });
     }
     else {
       var obj = {
         'contents' : contents,
         'name' : name,
         'title': title
       };

       diary_Ref.push(obj);
     }



   } // 


   var t = document.getElementById('d_submit');
    t.addEventListener('click', function(event){
      save_data();
      location.reload();

      if(userInfo){
        console.log('ok');

      }else{
        alert('x');
        location.reload();
      }
    });





}); // 



Aucun commentaire:

Enregistrer un commentaire