我想将img_thumb_url写入firebase数据库。在func1A中,我在下面编写了代码,我希望当全局变量room和msg_key不为null时,它可以突破while循环,但是我发现它始终是未定义的,尽管当func2B成功触发时,这些变量已使用字符串值定义了。
...
while(1){
if(room!=null && msg_key!=null){
console.log('room is ', room, '. msg_key is ', msg_key);
console.log('break from the loop');
break;
}
}
admin.initializeApp();
return admin.database().ref('/msgs/' + room + '/chat/' + msg_key + '/attachment/photo/thumbnail/url2').set(img_thumb_url);
})
但是''/ msgs /'+ room +'/ chat /'+ msg_key +'/ attachment / photo / thumbnail / url2'上方的路径取决于从此处的其他函数func2B检索到的变量room和msg_key,< / p>
exports.func2B = functions.database.ref('/msgs/{roomName}/chat/{pushid}')
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const msg = snapshot.val();
if (msg.attachPhotoUrl == null) {
console.log('No photo attachment found');
return null;
}
if (msg_key != null) {
console.log('msg_key no longer null');
return null;
}
console.log('writing url2 for thumbnail in firebase database...');
msg_key = msg.key;
room = msg.roomName;
console.log('room is ',room);
console.log('msg_key is ',msg_key);
console.log('img_thumb_url: ',img_thumb_url);
return ....
});
我不确定这是否是正确的方法,但我认为这不是那么简单。请帮我解决。如何将func2B中的赋值变量room和msg_key转换为func1A?