我有一个home
页面正在呈现,请求用户输入作为整数向量。我需要这些数据结构,因为它们与我将用来操作输入的数学函数配合得很好:
(defn home [& [weights grades error]]
(html
;; ...
(form-to [:post "/"]
;; ...
(text-area {:rows 15 :cols 30 :placeholder
"[89 78 63]
[78 91 60]
[87 65 79]
..." } "grades" grades)]
(submit-button "process"))]))
"process"
按钮通过一个defroutes
函数发送输入,使用一个方法POST
,该方法调用一个processed
渲染html
显示输入计算结果的方法。调用用于计算最终成绩列表的函数process-grades
。我正在尝试read-string
将输入数据结构更改为我的函数可以处理但无法使其工作的东西。当我用 替换调用processed
时,在点击按钮"TEST"
后渲染文本没有问题:process
(defn process-grades
"Takes user input from home's form-to function and processes it into the final grades list"
[weights grades]
(->> grades
(map (partial percentify-vector weights))
(mapv #(apply + %))))
(defn processed [weights grades]
(cond
(empty? weights)
(home weights grades "You forgot to add the weights!")
(empty? grades)
(home weights grades "You forgot to add the grades!")
:else
(do
(html
[:h2 "These are your final grades."]
[:hr]
[:p (process-grades (read-string weights)(read-string grades))])))) ;; <- This is not working!
(defroutes grade-routes
(GET "/" []
{:status 200
:headers {"Content-Type" "text/html"}
:body (home)
})
(POST "/" [weights grades] (processed weights grades))
(ANY "*" []
(route/not-found (slurp (io/resource "404.html")))))
我对html
form
标签、Clojure 的read-string
功能以及编写所需功能的各种脚本方式进行了一些研究。由于信息过多,我仍然想知道:最简单、最简洁、惯用的方法是什么?我应该使用 Clojurescript 还是可以在这里使用香草味的 JVM Clojure?