简体   繁体   English

带有 typeof 函数的 Firebase 推送数据返回错误

[英]Firebase push data with typeof function is return an error

Sorry for my English.对不起我的英语不好。

I am trying to add a post object, with a func property and a function value:我正在尝试添加一个具有func属性和函数值的post对象:

let ref = firebase.database().ref('posts');
let func = function(){ alert('hi!') }
ref.push({
    author: 'some name',
    func: func,
}); 

But when adding, I get an error:但是在添加时,我收到一个错误:

Uncaught Error: Firebase.push failed: first argument contains undefined in property 'posts.func'`.未捕获的错误:Firebase.push 失败:第一个参数在属性“posts.func”中包含未定义。

Although when I pass the text into the func property I have no error.虽然当我将文本传递到func属性时,我没有错误。 Please, help.请帮忙。

Realtime Database doesn't support storing function type values.实时数据库不支持存储函数类型值。 Values must be JSON-compatible: object, array, string, number, boolean, or null.值必须与 JSON 兼容:对象、数组、字符串、数字、布尔值或 null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM