我正在使用 clojure 和 hiccup(带有 noir),并且我有以下代码:
(defn dataframe [id]
(db/db-to-data id))
(defpartial drop-downs [nms]
(for [nm (keys nms)] (drop-down nm (get nms nm))[:br])
(submit-button "Refresh")
)
(defpage "/dataset/table/:id" {:keys [id]}
(common/layout
(form-to [:post (format "/dataset/table/%s" id)]
(drop-downs {"alessio" [:col0], "test" [:col1]})
)
(html-table (dataframe id))))
我的问题是:
(for [nm (keys nms)] (drop-down nm (get nms nm))[:br])
我想在我的表单中有多项选择。上面的行做到了这一点,但由于某种原因它没有考虑 [:br],所以它不会断行。但是,如果我这样做:
(form-to [:post (format "/dataset/table/%s" id)]
(drop-down "Test1" "1")[:br]
(drop-down "Test2" "2")[:br]
)
[:br] 标签确实有效。我相信这与 (for) 宏的工作方式有关,但我无法弄清楚原因以及如何解决它。
编辑
按照建议,我放弃了 for 的使用。下面的最终结果(这是带有轻微 mod 的 Joost 答案):
(mapcat #(vector (drop-down % (nms %)) [:br]) (keys nms))