-1
我与这个文件一起如下:的forEach功能不匹配的文件
https://www.firebase.com/docs/web/api/datasnapshot/foreach.html
基本上当我复制这样的例子:
var ref = new Firebase("https://FIREBASEID.firebaseio.com/users");
ref.once("value", function(snapshot) {
// The callback function will get called twice, once for "fred" and once for "barney"
snapshot.forEach(function(childSnapshot) {
// key will be "fred" the first time and "barney" the second time
var key = childSnapshot.key();
console.log(key);
});
});
不同的例子,你会期望得到
> Fred
> Barney
我反而得到
> First
> Last
> First
> Last
这是以上每个名称中的关键字。
我可以通过改变火力裁判这个修复:
var ref = new Firebase("https://FIREBASEID.firebaseio.com/");
为什么没有这方面的工作,如文档?
的例子给你'fred'不'Fred' - 一个重要的区别。 – Adam
你所描述的是按预期工作。你并没有严格按照这个例子来解释结果的差异。 –
嘿迪伦。欢迎来到堆栈溢出并感谢尝试Firebase。正如你可能已经注意到的那样,你会得到一些负面的反馈。为了防止这种情况发生,如果您向我们提供您正在使用的确切数据和代码,通常会有所帮助您可以通过单击“导出”按钮从Firebase仪表板获取数据。并且确保您显示您实际使用的代码。不要为该问题键入不同的代码。相反[在最小的数据集+代码中重现您的问题](http://stackoverflow.com/help/mcve)并共享这些内容。 –