javascript - 如果 Firestore 中的数字不是字符串,则无法打印字段值
问题描述
我需要将其打印在列表中:
li.setAttribute('data-id', updatesArgument.id);//'id' here unique id
Example 1
name.textContent = updatesArgument.data().count;// Works if String
Example 2
let i=1;
name.textContent = updatesArgument.data().i;//Does not work if Number
li.appendChild(name);
infoUpdates.appendChild(li);
图片将向您显示 1:“日期/错误修复”
这就是我想在列表上打印的内容:
解决方案
其他答案是正确的,但我还想补充一点,您的项目中可能存在一些转换问题,如果是这种情况,您必须将数字转换为字符串,一个简单的解决方法是
name.textContent = "" + updatesArgument.data()['count'];
或者
name.textContent = "" + updatesArgument.data()[1];
推荐阅读
- php - 使用 Imagick 将 PDF 页面转换为图像跳过最后一个 PDF 页面
- c# - 在 CodeDorProvider 的源代码中添加引用 ValueTuple
- javascript - 填充 SVG 圆圈的一半
- date - 如果在某个日期之后 - 过滤器列表
- sh - 等效于 sh 中的双括号
- r - 将矩阵中的值复制到 r 中的另一个位置
- bash - Docker,CentOS:如何在 bash shell 中使用环境模块自动加载模块?
- python - 如何将来自 url 的音频流直播到传出的 twilio 电话中?
- macos - Vulkan macOS 实例无法加载
- python - 使用 spotipy 在烧瓶会话中存储 Spotify 令牌?