我在为websql格式化ClojureScript包装时遇到了一些麻烦。主要问题是JavaScript使用了无法定义的websql的tx和err参数。当ClojureScript版本运行时,代码会抛出错误,因为tx未定义。下面是一些示例代码,以及我正在尝试的websql tutorial from PhoneGap:
(defn populateDB [tx]
(.executeSql tx ("CREATE TABLE IF NOT EXISTS foo (id unique, text)"))
(.log js/console "table added"))
(defn errorCB [err]
(.log js/console (str "There was an error" (.code err))))
(defn successCB []
(.alert js/window "It worked!"))
;; Run the transactions
(def db
(.openDatabase js/window "Database" "1.0" "Cordova Demo" 1024))
(.transaction db (populateDB) (errorCB) (successCB))
有没有办法让这个工作或者webql + ClojureScript已经存在的任何库?
答案 0 :(得分:2)
我猜这个问题有点愚蠢。在发布之前我应该更多地看一下:p。作为参考,这是写这个的一种方法:
(def db
(.openDatabase js/window "Database" "1.0" "Cordova Demo" 1024))
(.transaction db.
(fn [tx]
(.executeSql tx "CREATE TABLE IF NOT EXISTS DEMO (id unique, data)"))
(fn [err]
(.log js/console.
(str "There was an error " (.code err))))
(fn []
(.log js/console "It worked!")))