snapshot.ref不是一个函数 [英] snapshot.ref is not a function

查看:140
本文介绍了snapshot.ref不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从快照更新字段,但即使快照不是空的,并正确打印,我似乎无法使用 ref.update()就可以了。我试图按照

解决方案

问题在于您所引用的答案使用的是Firebase以前的版本, API非常接近当前版本,有一些区别。



有一个指南,其中讨论了从Firebase版本2和版本3升级时所做的更改以及需要执行的操作。



特别是,许多没有参数的获得者已被更改为只读属性

lockquote
BEFORE

  //参考
var key = ref.key();
var rootRef = ref.root();
var parentRef = ref.parent();

//查询
var queryRef = query.ref();
$ b // DataSnapshot
ref.on(value,function(snapshot){
var dataRef = snapshot.ref();
var dataKey = snapshot。 key();
});

AFTER

pre> //参考
var key = ref.key;
var rootRef = ref.root;
var parentRef = ref.parent;

//查询
var queryRef = query.ref; (value,function(snapshot){
var dataRef = snapshot.ref;
var dataKey = snapshot.key;
$ b // DataSnapshot
ref.on
});



I'm trying to update a field from a snapshot, but even though the snapshot is not null and printed correctly, I can't seem to use ref.update() on it. I tried to follow this answer. What am I missing here?

My code:

 ref.limitToLast(1).on('child_added', function(snapshot) {
    console.log(snapshot.val());
    var serial_number = String(snapshot.child("serial").val()); // 
    console.log(serial_number);
    snapshot.ref().update({ signed: 'true' });
// ...
}

Output:

解决方案

The problem is that the answer you are referencing uses the previous version of Firebase and whilst the API is very close to the current version, there are a few differences.

There is a guide that discusses the changes and what needs to be done when upgrading from Firebase version 2 and version 3.

In particular, many no-argument getters have been changed to read-only properties:

BEFORE

// Reference
var key = ref.key();
var rootRef = ref.root();
var parentRef = ref.parent();

// Query
var queryRef = query.ref();

// DataSnapshot
ref.on("value", function(snapshot) {
  var dataRef = snapshot.ref();
  var dataKey = snapshot.key();
});

AFTER

// Reference
var key = ref.key;
var rootRef = ref.root;
var parentRef = ref.parent;

// Query
var queryRef = query.ref;

// DataSnapshot
ref.on("value", function(snapshot) {
  var dataRef = snapshot.ref;
  var dataKey = snapshot.key;
});

这篇关于snapshot.ref不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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