亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在個人資料圖片下顯示名稱 Firebase Web Realtime-Database

在個人資料圖片下顯示名稱 Firebase Web Realtime-Database

慕娘9325324 2022-12-18 16:06:02
用戶特定信息個人資料圖片顯示我修復了以前遇到的大量錯誤。目標:動態顯示所有注冊用戶,并在他們的個人資料照片下顯示他們的名字。它現在做什么:在單獨的 div 中動態顯示所有用戶(當您單擊它時會顯示特定用戶信息)和個人資料圖片。圖片:顯示的動態圖片片段:const dbRef = firebase.database().ref();const usersRef = dbRef.child('userInfo');const userListUI = document.getElementById("userList");usersRef.on("child_added", snap => {  let user = snap.val();  let $h3 = document.createElement("h3");  $h3.innerHTML = user.name;  $h3.setAttribute("child-key", snap.key);  $h3.addEventListener("click", userClicked)  userListUI.append($h3);});function userClicked(e) {  var userID = e.target.getAttribute("child-key");  const userRef = dbRef.child('userInfo/' + userID);  const userDetailUI = document.getElementById("userDetail");  userDetailUI.innerHTML = ""  userRef.on("child_added", snap => {    var $p = document.createElement("p");    $p.innerHTML = snap.key + " - " + snap.val()    userDetailUI.append($p);  });}var storage = firebase.storage();var storageRef = storage.ref();$('#List').find('tbody').html('');var i = 0;storageRef.child('users').listAll().then(function(result) {  result.items.forEach(function(imageRef) {    i++;    displayImage(i, imageRef);  });});function displayImage(row, images) {  images.getDownloadURL().then(function(url) {    // console.log(url);    let new_html = '';    // new_html += '<tr>';    new_html += '<td>';    // new_html += '</td>';    // new_html += '<td>';    new_html += '<img src= "' + url + '">';    new_html += '</td>';    // new_html += '</tr>';    new_html += row;    $('#List').find('tbody').append(new_html);  });}<table id="List">  <tbody>  </tbody></table><br><br><ul id="userList"></ul><div id="userDetail">  <p>    <strong class="detailName"></strong>  </p></div>我為嘗試修復所做的工作:谷歌搜索,玩弄顯示圖像功能(嘗試移動 $('#List').find('tbody').append(new_html); 下面的第二個到最后一個}) ;) 向 new_html 添加一些內容以顯示名稱,但 images.getDownloadURL 弄亂了我嘗試過的其他內容,因為如果我在它之后或之前添加另一個功能,我會收到錯誤消息,因為圖像存儲在存儲中并且用戶信息是在實時數據庫中。任何指針?
查看完整描述

1 回答

?
楊魅力

TA貢獻1811條經驗 獲得超6個贊

 var userData = docRef.collection("userInfo");

 usersRef.on("child_added", snap => {

     let user = snap.val();

     let $ul = document.createElement("ul");

     $ul.innerHTML = user.name;

     $ul.setAttribute("child-key", snap.key);

     $ul.addEventListener("click", userClicked) 

     userListUI.append($ul);

 });

 function userClicked(e) {

   var userID = e.target.getAttribute("child-key");

   const imageRef = storageRef.child('users/' + userID);

   const userRef = dbRef.child('userInfo/' + userID);

   // window.location = 'profileview.html';

   const userDetailUI = document.getElementById("userDetail");

   userDetailUI.innerHTML = "";

   userRef.on("child_added", snap => {

       var $ul = document.createElement("ul");

       $ul.innerHTML = snap.key + " - " + snap.val() 

       userDetailUI.append($ul);

   });

 }


查看完整回答
反對 回復 2022-12-18
  • 1 回答
  • 0 關注
  • 123 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號