gpt4 book ai didi

javascript - 如何在 Clojurescript 中使用 firebase.push?我的数据正确吗?

转载 作者:数据小太阳 更新时间:2023-10-29 06:06:23 25 4
gpt4 key购买 nike

我正尝试将一些数据.push 到我的 Firebase,但我在 Chrome 控制台中收到此错误:

Uncaught Error: Firebase.push failed: first argument contains an invalid key (cljs$lang$protocol_mask$partition0$) in property 'arr.0'. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"

这是我的代码:

fb (js/Firebase. "https://example.firebaseio.com/example-listings")

(def app-state (atom {"post" { :first_name "Billy"
:last_name "Bob"
:location "CA"
:email "bob@aol.com"
:website "www.pwt.com"
}}))

(def postData (get-in @app-state ["post"]))
(.push fb postData)

我还尝试用 "first_name" 替换字符串 :first_name 的键。我知道 Clojure 的数据结构与 JavaScript 有点不同。是不是 Firebase 不喜欢我的 Clojure map ?

最佳答案

Firebase 需要一个 JavaScript 对象来调用它的 API。您正在向它传递 Clojure 数据结构(在本例中为 map )。在将 Clojure 数据结构传递给 Firebase 函数之前,您必须将其转换为 JavaScript 对象。

所以代替:

(.push fb postData)

你需要做的:

(.push fb (clj->js postData))

关于javascript - 如何在 Clojurescript 中使用 firebase.push?我的数据正确吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27599452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com