firebase在删除之前获取父数据的父项 [英] firebase get parrent of parent data before delete
问题描述
我尝试使用此代码,但无法正常工作
var idUser = event.data.ref.parent.ref.parent .child( 'ID用户所')previous.val();
然后我试着用
event.data.ref.parent.ref.parent.child('idUser')。onDelete(event => {
event.data.previous.val() ;
});
这是我的完整代码
<$ p $ ($ / $ {
var / $> previous.val();
var quantity = event.data.child('quantity')。previous.val();
var idUser = previous.val();
var refUser = db.ref('/ user_data /'+ idUser +'/ purchaseSummary /'+ name.toUpperCase());
refUser.once(value,function(snapshotUser){
),function(errorObject){
console.log(The read失败:+ errorObject.code);
});
return true;
});
当你向上父母
链时,你将不得不通过附加一个监听器来显式加载数据。这和你已经在你的问题中已经做了很相似的事情: firebase云功能函数循环在执行中
不幸的是,你不能得到层次结构中高于你触发函数的值的前一个值。 $ b
I try to using this code but not working
var idUser = event.data.ref.parent.ref.parent.child('idUser').previous.val();
then I get an error when try using
event.data.ref.parent.ref.parent.child('idUser').onDelete(event => {
event.data.previous.val();
});
This is my full code
exports.makePurchaseSummaryDelete = functions.database.ref('/invoice_data/{pushIdInvoice}/item/{pushIdItem}')
.onDelete(event => {
var name = event.data.child('itemName').previous.val();
var quantity = event.data.child('quantity').previous.val();
var idUser = event.data.ref.parent.ref.parent.child('idUser').previous.val();
var refUser = db.ref('/user_data/' + idUser + '/purchaseSummary/' + name.toUpperCase());
refUser.once("value", function(snapshotUser) {
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
return true;
});
Database events are automatically passed any data for the node the event triggered (and downwards).
When you go up the parent
chain, you will have to explicitly load the data by attaching a listener. That's quite similar to what you already did in your question here: firebase cloud function function looping in execution
That unfortunately means that you cannot get the previous value for nodes higher in the hierarchy than where you triggered the function.
这篇关于firebase在删除之前获取父数据的父项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!