表按下按钮时删除

时间:2016-12-21 15:16:32

标签: clojure clojurescript

我无法在表格中交换值。当我按下按钮而不是更改的值时,整个表格被删除,我无法弄清楚原因。以下是我的代码。 (rt指冷冻锁https://github.com/Frozenlock/reagent-table的试剂表)

(ns <namespace name>
  (:require [reagent.core :as reagent :refer [atom]]
            [reagent-table.core :as rt]
            [clojure.walk :as walk]))

(def table-data {:headers ["1" "2" "3" "4"]
                 :rows [["A"]]})

(defonce tdata (atom table-data))

(defn replace-value [struct]
  (walk/prewalk-replace {"A" "hello"} (struct :rows)))

(defn change-value [tdata]
  [:div
   [:input.btn.btn-primary
    {:type     :submit
     :on-click #(swap! tdata replace-value)
     :value    "Change"}]
   ])

(defn tablescreen []
  [:div
   [:div.container
    [:div.span12
     [rt/reagent-table tdata]
     [change-value tdata]]]
   ])

最初在屏幕上显示表格。但是,当按下按钮时,我预计&#34; A&#34;改为&#34;你好&#34;。但是,按下按钮时,整个表格将从视图中删除,只剩下按钮

0 个答案:

没有答案