我不想在中的{id}下获取所有值。onUpdate((var3是嵌套对象,而var2是单个变量。那么,我如何从onUpdate中检索{id},并将其作为参数传递给customMethod,以便在admin.ref((中使用它呢?
index.ts
export const funcName = functions.region("someRegion").database.ref('/user/{id}/var3').onUpdate((change, context) =>{
const originalData = <varType> change.after.val();
const processedData = customMethod(originalData);
if(change.after.ref.parent)
return change.after.ref.parent.child('custom').set(processedData);
else
return null;
});
function customMethod(data: varType){
return admin.database().ref('/user/{id}/var2').once('value').then(function(snapshot){
// processing stuff after storing value from var2 in a local variable
}
开始工作了。。。引用了父节点,并将引用作为参数发送。
const originalData = <varType> change.after.val();
const splRef = <admin.database.Reference> change.after.ref.parent
const processedData = customMethod(originalData,splRef);
function customMethod(data: varType,dbref: admin.database.Reference){
return admin.database().dbref.once('value').then(function(snapshot){
// processing stuff after storing value from var2 in a local variable
}
@雷诺,谢谢你!!