收款人不断向我索取"undefined"信息, [英] collections keeps retrieving me "undefined"

查看:44
本文介绍了收款人不断向我索取"undefined"信息,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法获取快照文档来向我显示来自服务器的数据.

I just cant seem to get the snapshot docs to show me the data from the server.

我已经检查了收藏集.它被称为"creaciones" ,不带大写字母.我有1个文档,并且已经编写了文件.我没有任何拼写错误.我以前做过这项工作,现在我做不到.

i have checked the collection. it is called "creaciones" without uppercase. I have 1 document and I have files written already. I've made no spelling mistakes whatsoever. I made this work before and now i cant.

db.collection('usuarios').get().then(function(querySnapshot) {
    querySnapshot.forEach(function(doc){
        console.log(doc.data);
    });
    setupGrilla(snapshot.docs);

});

//Setup grilla
const setupGrilla = (data) => {

    let html = '';
    data.forEach(doc => {
        const grilla = doc.data();
        const creacion = `
    <div>
        <img src='jpg/${grilla.tipoCreacion}.png' alt='tipoCreacion'>
        <h2>${grilla.nombreCreacion}</h2>
        <img src='Imagenes/${grilla.nombreFoto}' alt='nombrefoto' class='imagen'>
        <span>piezas: ${grilla.piezas}</span>
        <span class='separador'></span>
        <span>tiempo: ${grilla.tiempo} minutos</span>
        <p>padre: ${grilla.ayuda} </p>
        <p class='puntos'>Puntos: ${grilla.puntos} </p>
    </div>
        `;
        html += creacion;
    });

}

//get Data
db.collection('creaciones').get().then(snapshot => {
        setupGrilla(snapshot.docs);
        console.log(snapshot.docs);
});

我希望它能显示获取数据库数据.

I expect it to show fetch the database data.

推荐答案

您正在使用 snapshot.docs 参数调用 setupGrilla ,但使用 snapshot 从未定义.

You are calling setupGrilla with a snapshot.docs argument, but snapshot is never defined.

改为尝试 querySnapshot.docs ,或在 snapshot 中重命名 querySnapshot .

Try querySnapshot.docs instead, or rename querySnapshot in snapshot.

您还将错误的参数传递给方法

You are also passing the wrong argument to your method

db.collection('usuarios').get().then(function(snapshot) {
    snapshot.forEach(function(doc){
        console.log(doc.data);
    });
    setupGrilla(snapshot); // <-- Here

});

这篇关于收款人不断向我索取"undefined"信息,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆