Firebase承诺 - Query.once失败:使用1个参数调用。预计至少2 [英] Firebase promise - Query.once failed: Was called with 1 argument. Expects at least 2

查看:86
本文介绍了Firebase承诺 - Query.once失败:使用1个参数调用。预计至少2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用承诺从Firebase中填充一些数据。这里是数据库结构:

pre $ - 域名(或者其他)
| - 高分
| - -Foo:50
| --Bar:60

代码:

  var arr = []; 
highscoreRef.child('highscore')。once('value')。then(function(snapshot){
snapshot.forEach(function(data){
arr.push({playerName :data.key(),score:data.val()});
});
},function(error){
console.error(error);
});

我得到未捕获的错误:Query.once失败: 。至少2。



这是否意味着我必须添加至少2个属性到Foo和Bar?防爆。



目前的数据库安排符合我的需求。


<当您尝试在预Promisified SDK上使用Promisified API时,会出现此错误消息。



回调(其他答案建议)可以在任何2.x版本的Firebase SDK上使用。

我们在Firebase的JavaScript SDK版本2.4中引入了一种使用promise的替代语法。在这个jsbin中查看的例子once()。then() http://jsbin.com/qiranu/edit?js,console

您是否使用Firebase JavaScript SDK版本2.4或更高版本(这是承诺引入的地方)?

I'm trying to fill an array with some data from Firebase using promises. Here's the DB structure:

- domain name(or something)
  |--highscore
     |--Foo: 50
     |--Bar: 60

The code:

var arr=[];
highscoreRef.child('highscore').once('value').then(function(snapshot) {
    snapshot.forEach(function(data) {
    arr.push({playerName: data.key(), score: data.val()});
    });
  }, function(error) {
     console.error(error);
});

I get Uncaught Error: Query.once failed: Was called with 1 argument. Expects at least 2.

Does that mean I have to add at least 2 properties to Foo and Bar? Ex. Foo = {playerName: name, score: 50}

The current DB arrangement fits my needs.

解决方案

This error message happens when you try to use the Promisified API on a pre-Promisified SDK.

Callbacks (that other answers have suggested) will work on any 2.x version of the Firebase SDK.

We introduced an alternative syntax using promises in Firebase's JavaScript SDK version 2.4. See an example of once().then() in this jsbin: http://jsbin.com/qiranu/edit?js,console

Are you using Firebase JavaScript SDK version 2.4 or later (that's where promises were introduced)?

这篇关于Firebase承诺 - Query.once失败:使用1个参数调用。预计至少2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆