通过使用Node.js的Google Cloud Functions for Firebase,我试图在两个嵌套的foreach循环中获取当前deltasnapshot的键。
第一级密钥是正确的“传入”
第二级无效'incomingABCDEFGHI‘// ABCDEFGHI是帐户的唯一id
三级密钥正确'-ewroiu5o345o534535‘// Firebase推流ID
console.log(snapshot.key);
snapshot.forEach(function(accountSnapshot){
accountSnapshot.forEach(function(orderSnapshot){
console.log(snapshot.key);
console.log(accountSnapshot.key);
console.log(orderSnapshot.key);
});
});出于某种原因,二级键同时返回一级键和二级键的组合(没有斜杠或空格)
DeltaSnapshot由数据库'onWrite‘触发
有没有人有类似的东西?
发布于 2017-04-14 13:59:19
我也遇到了同样的问题。如果我的路径是'1/2/ 3 ',键将输出23而不是3。他们有一个方法可以输出子对象的完整路径,而且他们似乎省略了那个斜杠。将此代码添加到index.js文件的顶部:
const functions = require('firebase-functions');
functions.database.DeltaSnapshot.prototype._fullPath = function () {
var out = (this._path || '') + '/' +(this._childPath || '');
if (out === '') {
out = '/';
}
return out;
}我在GitHub上提交了一个问题,它可以在here上找到。
https://stackoverflow.com/questions/43113839
复制相似问题