2017-02-26 1 views
4

Ich möchte alle meine Bilder von Firebase Storage auf einem Tisch anzeigen. Es scheint mir schwer zu fallen, in JavaScript. Es gibt mir eine Fehlermeldung:Alle Bilder aus dem Speicher in Firebase anzeigen

Firebase Storage: Object 'Item_Images/' does not exist.

var fbRef = firebase.database().ref().child("Item Posts"); 
var storage = firebase.storage().ref(); 
var storageRef = storage.child("Item_Images/"); 

fbRef.on("child_added", snap => { 
    var name = snap.child("ItemName").val(); 
    var price = snap.child("Price").val(); 
    var category = snap.child("Category").val(); 
    var description = snap.child("Description").val(); 
    var image = storageRef.getDownloadURL().then(function(url){ 
     var test = url; 
     document.querySelector('img').src = test; 
    }) 

    $("#tableBody").append("<tr><td>" + image + "</td><td>" + name + "</td><td>" + price + "</td><td>" + category + "</td><td>" + description + "</td></tr>"); 
}); 

HTML

<table> 
    <tr class="heading"> 
     <td width="20%">Image</td> 
     <td width="20%">Name</td> 
     <td width="10%">Price</td> 
     <td width="15%">Category</td> 
     <td width="35%">Description</td> 
    </tr> 
    <!-- display data here --> 
    <tbody id="tableBody"></tbody> 
</table> 

Hier ist meine Datenbank:

database

und hier ist meine aktuelle HTML-Tabelle:

HTML Table

Antwort

1

Uhh .. es stellt sich heraus, dass ich das selbst behoben habe. Ich werde die Antwort hier posten, damit es anderen Leuten helfen kann.

var fbRef = firebase.database().ref().child("Item Posts"); 
//removed the storage reference 

fbRef.on("child_added", snap => { 
    var name = snap.child("ItemName").val(); 
    var price = snap.child("Price").val(); 
    var category = snap.child("Category").val(); 
    var description = snap.child("Description").val(); 
    //got the string URL from the database 
    var image = snap.child("Image").val(); 

    //concatenated the img tag using the image variable at the top 
    $("#tableBody").append("<tr><td><img src=" + image + "/img></td><td>" + name + "</td><td>" + price + "</td><td>" + category + "</td><td>" + description + "</td></tr>"); 
}); 
Verwandte Themen