我正在看下面的教程

https://developer.apple.com/library/iad/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/UsingtheJavascriptDatabase/UsingtheJavascriptDatabase.html

并在dataHandler函数中将js转换为cljs时遇到麻烦

function dataHandler(transaction, results)
{
// Handle the results
var string = "Green shirt list contains the following people:\n\n";
for (var i=0; i<results.rows.length; i++) {
    // Each row is a standard JavaScript array indexed by
    // column names.
    var row = results.rows.item(i);
    string = string + row['name'] + " (ID "+row['id']+")\n";
}
alert(string);
}


这是我的cljs代码

 (defn success-handler [tx, results]
   (println "success handler")
   (println results)

   ;;the below doesn't work, I get an error here
   ;;:Uncaught Error: [object SQLResultSet] is not ISeqable

  (doseq [result results]
  (prn result)))


所以我的问题是如何将js dataHandler转换为cljs成功处理程序?

最佳答案

尝试将结果的行变成一个序列,而不是整个结果。

(defn success-handler [tx, results]
   (println "success handler")
   (println results)

  (doseq [result (.-rows results)]
    (prn result)))


如果行未实现Iterable,则以老式方式进行

(defn success-handler [tx, results]
   (println "success handler")
   (println results)

  (let [rows (.-rows results)]
   (doall
    (for [i (range (.-length rows))]
      (let [row (nth rows i)]
        (prn result))))))

09-25 20:29