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

Abierto
#674 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
javascript
Área
database

Línea de trabajo

Empieza leyendo el script de módulo inline del HTML proporcionado y js2.js, y después reproduce el error de firebase.database con el flujo de actualización mostrado. Compara las importaciones de Firebase y la inicialización con el punto de entrada de actualización; se considera terminado cuando el registro de UsersList se actualiza sin el TypeError indicado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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');

};

Lenguaje dominante
JavaScript
Estrellas
1.9k
Forks
1.8k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de firebase/codelab-friendlychat-web

Todos los issues de firebase/codelab-friendlychat-web

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.