【发布时间】:2017-05-15 22:07:46
【问题描述】:
我一直在尝试总结价格,以通过新的 Firebase 云功能得出总数
"Cart" : {
"-Ksdasd50oR04q073k5" : {
"ID" : 0.01,
"price" : 20
},
"-KhOc0CGdsddihGB2N" : {
"ID" : 001,,
"price" : 20
},
这是我的开始,
exports.cartadd = functions.database.ref('Cart/{uid}').onWrite(event => {
let ref = admin.database().ref('Cart/{uid}');
return ref.once('value').then(snapshot => {
if (snapshot.hasChildren()) {
var total= 0;
snapshot.forEach(function(child) {
total += snapshot.val().price;
});
console.log(total);
}
});
【问题讨论】:
-
在什么条件下需要计算这个总和?
标签: firebase firebase-realtime-database google-cloud-functions