Am getting the error of firebase.database is not a function when tryna use update syntax using javascript. here are my 2 files

Aperta
#674 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript
Ambito
database

Direzione di ricerca

Inizia leggendo lo script di modulo inline nell’HTML fornito e js2.js, quindi riproduci l’errore firebase.database con il flusso di aggiornamento mostrato. Confronta gli import di Firebase e l’inizializzazione con il punto di ingresso dell’aggiornamento; il lavoro è completato quando il record UsersList viene aggiornato senza il TypeError segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

codelab
<title>Retrieve</title>
    <style>
        .labs{
            display: inline-block;
            width: 100px;
        }
    </style>
</head>

NFC MTC GRAB CUSTOMERS

MTC GRAB
<div class="container mt-3">
    
    <div class="input-group mb-3">
        <input id="SearchBar" type="text" class="form-control" placeholder="Search using the" aria-label="Recipient's username" aria-describedby="button-addon2">
        <div class="input-group-append">
            <select class="custom-select" id="CategorySelected">
                <option selected value="1">name</option>
                <option value="2">username</option>
                <option value="3"> email</option>
                <option value="4"> password</option>
              </select>
          <button id="SearchBtn" class="ml-1 btn btn-outline-info" type="button" id="button-addon2">SEARCH</button>
        </div>
      </div>

Back
                                     
Add User
   
Add driver
Driver's list








        </thead>
        <tbody  id="tbody1">
            


</div>
Control Pannel
× Full name:
Username:
Email:
Password:
    <div class="modal-footer">
      <button id="AddModBtn" type="button" class="btn btn-info"  onclick="Addstd()">Add</button>
      <button  id="UpdModBtn" type="button" class="btn btn-success" onclick="Updstd()">Update</button>
      <button  id="DelModBtn" type="button" class="btn btn-danger" onclick="Delstd()">Delete</button>
    </div>
  </div>
</div>
Sno Full Name Username email password Control Center
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script type="module">
    
    function AddItemToTable(fullname,username,email,password) {
    var tbody = document.getElementById("tbody1");
        let tr = document.createElement("tr");
        let td0 = document.createElement("td");
        let td1 = document.createElement("td");
        let td2 = document.createElement("td");
        let td3 = document.createElement("td");
        let td4 = document.createElement("td");
        stdList.push([fullname,username,email,password]);
        td0.innerHTML = ++stdNo;
        td1.innerHTML = fullname;
        td2.innerHTML = username;
        td3.innerHTML = email;
        td4.innerHTML = password;
        td1 .classList +="nameField";
        td2.classList +="dateField";
        td3.classList +="timeField";
        td4.classList +="phoneField";
        tr.appendChild(td0);
        tr.appendChild(td1);
        tr.appendChild(td2);
        tr.appendChild(td3);
        tr.appendChild(td4);
        var ControlDiv = document.createElement("div");
        ControlDiv.innerHTML = '<button  type="button"  class="btn btn-info" my-2 ml-2" data-toggle="modal" data-target="#exampleModalCenter" onclick = "FillTboxes('+stdNo+')"> Edit </button>';
        ControlDiv.innerHTML += '<button  type="button"  class="btn btn-info" my-2 ml-2" data-toggle="modal" data-target="#exampleModalCenter" onclick = "FillTboxes(null)"> Add </button>';
        
    
        tr.appendChild(ControlDiv);
        tbody.appendChild(tr);
    }  

    function AddAllItemsToTable(TheStudent) {
        stdNo = 0;
        tbody.innerHTML = "";
        TheStudent.forEach(element => {
            AddItemToTable(element.fullname, element.username, element.email,element.password );
        });
    }

//............................................gettign data........................//
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.3/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.8.3/firebase-analytics.js";

                const firebaseConfig = {
                    apiKey: #######
                    authDomain: #############
                    databaseURL: ############
                    projectId: #########
                    storageBucket: ###########
                    messagingSenderId: #########
                    appId: ########
                    measurementId: #########
                };

                // Initialize Firebase
                const app = initializeApp(firebaseConfig);
                
                var stdNo;
                import  {getDatabase, ref , child, onValue, get}
                from  "https://www.gstatic.com/firebasejs/9.8.3/firebase-database.js";
            
               const db = getDatabase();
            
            
                function GetAllDataOnce(){
                    document.getElementById("tbody1").innerHTML="";
                stdNo = 0;
                    const dbref = ref(db);

                get(child(dbref, "UsersList"))
                .then((snapshot)=>{

                    var students =[];
                    snapshot.forEach(childSnapshot =>{
                        students.push(childSnapshot.val());
                    });

                    AddAllItemsToTable(students);
                });
        }

        window.onload = GetAllDataOnce;


        var searchBar = document.getElementById("SearchBar");
        var searchBtn = document.getElementById("SearchBtn");
        var category = document.getElementById("CategorySelected");
        var tbody = document.getElementById("tbody1");

        function SearchTable(Category){

            var filter = searchBar.value.toUpperCase();
            var tr = tbody.getElementsByTagName("tr");
            var found;

            for (let i = 0; i < tr.length; i++) {
                var td = tr[i].getElementsByClassName(Category);
                
                for ( let j = 0;  j < td.length; j++) {
                    if(td[j].innerHTML.toUpperCase().indexOf(filter) > -1){
                        found=true;
                    }
                    
                }

                if(found){
                    tr[i].style.display="";
                    found=false;

                }
                else{
                    tr[i].style.display="none";
                }
            }

        }

        searchBtn.onclick = function(){
            if(searchBar.value==""){
                SearchTable("nameField");
            }

            else if(category.value==1)
            SearchTable("nameField");

            else if(category.value==2)
            SearchTable("dateField");

            else if(category.value==3)
            SearchTable("timeField");

            else if(category.value==4)
            SearchTable("phoneField");
        };
       
</script>


 <script src="js2.js"></script>

var firebase= {
apiKey: ########
authDomain: ###########
databaseURL: #############
projectId: ########
storageBucket: ##########
messagingSenderId:#########
appId: ############
measurementId: ###########
};

var stdNo = 0;
var stdList =[];
var ModName = document.getElementById('NameMod');
var ModRoll = document.getElementById('RollMod');
var ModSec = document.getElementById('SecMod');
var ModPass = document.getElementById('PassMod');

var BTNmodAdd = document.getElementById('AddModBtn');
var BTNmodUpd = document.getElementById('UpdModBtn');
var BTNmodDel = document.getElementById('DelModBtn');
function FillTboxes (index){
if(index==null){
ModName.value = "";
ModRoll.value = "";
ModSec.value = "";
ModPass.value = "";
BTNmodAdd.style.display='inline-block';
BTNmodUpd.style.display='none';
BTNmodDel.style.display='none';
}else{
--index;
ModName.value = stdList[index][0];
ModRoll.value = stdList[index][1];
ModSec.value = stdList[index][2];
ModPass.value = stdList[index][3];
ModPass.disabled = true;
BTNmodAdd.style.display='none';
BTNmodUpd.style.display='inline-block';
BTNmodDel.style.display='inline-block';

}
}
function Updstd(){
firebase.database().ref('UsersList/'+ModRoll.value).update(
{
fullname: ModName.value,
username: ModRoll.value,
email : ModSec.value,
password : ModPass.value
},
(error) =>{
if(error){
alert("failed to update the records");
}else{
alert("success updated");
GetAllDataOnce();
$("exampleModalCenter").modal('hide');

        }
    }
)

}

function Delstd(){
firebase.database().ref('UsersList/'+ModRoll.value).remove()

        alert("deleted successfully");
            GetAllDataOnce();
            $("exampleModalCenter").modal('hide');

};

Lingua principale
JavaScript
Stelle
1.9k
Fork
1.8k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di firebase/codelab-friendlychat-web

Tutte le issue di firebase/codelab-friendlychat-web

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.