【问题标题】:Select/unselect checkbox in re-frame在重新框架中选择/取消选择复选框
【发布时间】:2020-04-20 23:58:00
【问题描述】:

我正在向我的 app-db 添加一个搜索 id 元素:

[:input {:type "checkbox" :on-change #(reframe/dispatch [:add-elm {:subject_id subject-id}])}]

但我不知道如何识别最终用户何时选中或取消选中该框以便从 app-db 放置或撤出元素。我想避免在 app-db 中搜索以查看该元素是否已经存在。

【问题讨论】:

  • 为什么要避免这种情况?这是一个非常好的订阅用例
  • 您还可以查看 fork 表单库,它可以更轻松地处理表单

标签: clojurescript reagent re-frame


【解决方案1】:

1) 在复选框中添加一个 ID:

   [:input {:type "checkbox" :title (:subject row-subject) 
          :id (str "subjects_" (:id row-subject))
          :on-change #(rf/dispatch [:add-search-elm {"subjects" (:id row-subject)}])}]   

2) 获取并读取 DOM 元素:

 (let [ksection  (first (first updates))  ;; key subject
      vsection  (get updates ksection)   ;; value subject
      elm       (str ksection "_" vsection)
      checkbox  (gdom/getElement elm)
      checked   (.. checkbox -checked)]
     (.log js/console (str ">>> ksection >>>>> " ksection  ";;  vsection >> " vsection  ";;  elm >> " elm "   checkbox >>> " checkbox ";; checked >> " checked))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-21
    • 2014-06-29
    • 2012-06-27
    • 1970-01-01
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多