我在 onCreate 触发后创建了一个发送电子邮件的函数,但在尝试访问值后出现了问题exports.sendEmailConfirmation = functions.database.ref('/contact').onCreate(async (snapshot, context) => { const val = snapshot.val(); console.log(val); const mailOptions = { from: val.name, to: 'kris@gmail.com', title: val.message,};try { await mailTransport.sendMail(mailOptions); console.log(`New ${val.message ? '' : 'un'} message sent to:`, val.email);} catch (error) { console.error('There was an error while sending the email:', error);}return null; });未定义新的联合国消息发送到:未定义然后尝试控制台似乎有一个想要引用但随机的密钥{ '-LuFhQVjr-T7UFYioi-d': { email: 'Kris@gmail.com', message: 'Hello cloud function', name: 'Kris' } }尝试再次使用传播,但有更多的问题功能没有触发我如何访问这个?
1 回答
凤凰求蛊
TA贡献1825条经验 获得超4个赞
当在 /contact. 在这种情况下,您希望在声明中包含新子节点路径的占位符:
exports.sendEmailConfirmation = functions.database
.ref('/contact/{pushid}')
.onCreate(async (snapshot, context) => {
const val = snapshot.val();
console.log(val);
const mailOptions = {
from: val.name,
to: 'rferfe@gmail.com',
title: val.message,
};
...
添加回答
举报
0/150
提交
取消