未捕获(在承诺中)TypeError.Cannot读取null的'innerHTML'属性?无法读取null的'innerHTML'属性?

我试图从云火库中获取图片URL和名称,但检索失败,网页上没有显示任何值。在检查后,正确的值被打印在控制台内,但随着控制台在innerHTML中显示一些错误。有谁可以概述这两个代码(Html& Js),并告诉我哪里是错误和错误,我已经做了?

错误。

defualt.js:22 Uncaught (in promise) TypeError: Cannot read property 'innerHTML' of null
at defualt.js:22
at database.ts:2202
at document_set.ts:97
at Wg.ut (sorted_map.ts:324)
at Wg.ut (sorted_map.ts:323)
at Hg.ut (sorted_map.ts:136)
at k_.forEach (document_set.ts:96)
at gN.forEach (database.ts:2201)
at defualt.js:8

Can anyOne please reffer me how to fetch ImageUrl from cloud firestore database to website. 我正在做一个网站,这个网站只会把用户的资料图片和名字放在一起,然后显示在网站里面。我已经上传了图像在firebase存储和保存ImageUrl链接在云firefstore数据库内。我只是想检索已经存储在我的云数据库内的Profile图像和名称。

请帮助我,我面临着这个问题,从过去的5天,它会是触手可及的,我找到的结果。我已经阅读了firestore的文档,但它不是很有帮助的我。我已经尝试下面的代码,但它是不工作的存储值是不

Js代码。

db.collection("student entry").get().then(function(querySnapshot) {
  querySnapshot.forEach(function(doc) {
      // doc.data() is never undefined for query doc snapshots
      console.log(doc.id, " => ", doc.data());

      var posts_div=document.getElementById('#posts');
 posts.innerHTML="";
 var data=doc.data();
 console.log(data);
for(let[key,value] of Object.entries(data)){
posts_div.innerHTML="<div class='col-sm-4 mt-2 mb-1'>"+
"<div class='card'>"+
"<img src='"+value.image+"' style='height:250px;'>"+
"<div class='card-body'><p class='card-text'>"+value.fname+"</p>"+
"<button class='btn btn-danger' id='"+key+"' onclick='delete_post(this.id)'>Delete</button>"+
"</div></div></div>"+posts_div.innerHTML;

}
  });
});

HTML代码。

<html>
    <head>
        <title>Blogs</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    </head>
    <body>
        <div class="container mt-2">

            <div class="row mt-4" id="posts">

            </div>

        </div>

<!-- The core Firebase JS SDK is always required and must be listed first...make sure you remove -app from below line -->
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase.js"></script>

<script>
    // Initialize Firebase
    var config = {
        apiKey: " ",
        authDomain: " ",
       databaseURL: " ",
       projectId: " ",
       storageBucket: " ",
      messagingSenderId: " ",
      appId: " ",
      measurementId: " "
    };
    firebase.initializeApp(config);
    var db = firebase.firestore();
    db.settings({ timestampsInSnapshots: true }); 
</script>


        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
        <script src="defualt.js"></script>
    </body>
</html>

enter image description here

解决方案:

你不需要 # 当使用 getElementById. document.getElementById('posts'); 应该可以。

给TA打赏
共{{data.count}}人
人已打赏
未分类

如何将一个对象映射到一个对象中

2022-11-11 7:53:31

未分类

运行到错误 "拒绝访问路径'C:\Users\Work & School\Documents\My Music'。" C#-App控制台

2022-11-11 7:53:33

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索