我无法使用 clojurescript / 试剂让我的桌子主体正确排列。我实际上不确定这是否是我不明白在 html 中做什么或什么......
目前我使用循环显示表格主体
(defn table-body [list-of-maps]
[:tbody
(for [one-map list-of-maps]
[:tbody
[:tr
[:td (:key1 one-map)]
[:td (:key2 one-map)]
[:td (:key3 one-map)]
[:td (:key4 one-map)]
[:td (:key5 one-map)]
[:td (:key6 one-map)]
[:td (:key7 one-map)]]
[:tr
[:td (:key8 one-map)]]])])
问题是我需要使用一些html元素在for之外和for内部进行分组,对吗?如果我在两者上都使用 [:tbody] ,它会弄乱与 [:thead] 部分的对齐。如果我使用 tbody 以外的元素,那么它会产生各种其他问题。如果我删除 for 循环中的 [:tbody] 和最后一个 [:tr],一切看起来都很好。
编辑:我目前已经缩小了很多问题。我的应用程序 ajax 获取和取消引用与表相关的数据。在此重新渲染时,表格的格式会变得混乱。
Edit2:我发现了问题。
(defn test-body [list-of-maps]
[:tbody
(for [one-map @list-of-maps]
[:tbody
[:tr
[:td (:key1 one-map)]
[:td (:key2 one-map)]
[:td (:key3 one-map)]
[:td (:key4 one-map)]
[:td (:key5 one-map)]
[:td (:key6 one-map)]
[:td (:key7 one-map)]]
[:tr
[:td (:key8 one-map)]]])])
(defn test-head []
[:thead
[:th "key1"]
[:th "key2"]
[:th "key3"]
[:th "key4"]
[:th "key5"]
[:th "key6"]
[:th "key7"]])
(defn test55 []
(let [list-of-maps (reagent/atom [])]
(js/setTimeout (fn [] (reset! list-of-maps '({:key1 "a1" :key2 "a2" :key3 "a3" :key4 "a4" :key5 "a5" :key6 "a6" :key7 "a7" :key8 "a8"} {:key1 "b1" :key2 "b2" :key3 "b3" :key4 "b4" :key5 "b5" :key6 "b6" :key7 "b7" :key8 "b8"}))) 3000)
[:table
[test-head]
[test-body list-of-maps]]))
当地图列表重新渲染表格的对齐方式时。