我想在父
中分配const
名称值
exports.myFunction = functions.database.ref('/messages/{pushId}/likes')
.onWrite(event => {
const name = event.parent.data.val().name; // this doesn't work. how do I properly get the name which is located in /messages/{pushId} ?
});
答案 0 :(得分:3)
根据the documentation,这是您从其他路径访问数据的方式:
exports.myFunction = functions.database.ref('/messages/{pushId}/likes')
.onWrite(event => {
return event.data.ref.parent.child('name').once('value').then(snapshot => {
const name = snapshot.val();
});
});
答案 1 :(得分:0)
版本更新后
事件< - (更改,上下文)
event.data< -change.after
exports.myFunction = functions.database.ref('/messages/{pushId}/likes')
.onWrite((change, context) => {
return change.after.ref.parent.child('name').once('value').then(snapshot => {
const name = snapshot.val();
});
});