javascript - firestore 获取字段以发挥作用
问题描述
所以我早些时候提出了一个关于从 Firestore 获取字段的问题。并且它在日志中正常工作。
但我试图找到一种方法将我的代码的获取名称设置为函数
这是代码
db.collection('users').doc('' + sender_id).get().then(doc=>{
if (!doc.exists) {
console.log('No Such document exists');
}
// do stuff with data smiley face.
(doc.data().name);
console.log('So it got your name correctly' + doc.data().name);
}).catch(err=>{
console.error('error getting document', err);
process.exit();
});
这就是我想要实现它的方式。
function welcome(agent) {
agent.add(+Getname + `,
Welcome to my chat bot.`);
}
所以我假设将第一个代码包装在
const getname = "firstcodehere";
但我认为这并不像 iv 多次尝试那样容易。没有运气。必须有一种简单的方法来在多个实例中重用第一个代码,只需一个常量名称。
解决方案
事实证明,除了将整个代码包装在此函数中以便它直接返回信息外,几乎没有办法解决这个问题。
那么你可以使用 const "something" = doc.data().name;
所以你可以使用 + something + ' 你的名字对吗?'
感谢所有的帮助。:) 希望这个答案在未来对其他人有所帮助。
推荐阅读
- opengl - 片段着色器中的纹理函数给出错误
- css - 如何在一个屏幕上编写响应式单页应用程序?
- visual-studio-code - vscode-remote-release 和 wsl 2
- mysql - 如何在检查约束中编写多个条件?
- r - 将日期和时间合并/汇总到 x 分钟块
- c - 枚举从值返回到名称以进行连接
- java - 在多线程环境中用 C# 和 Java 编写时获得相同程序的不同输出
- c - 包含按位运算符的代码未通过测试用例
- android - 单击通知“启动活动”时,Android 中的 Bundle savedInstanceState 为 null
- bash - 在 bash 代码中出现错误的替换错误