如何正确访问试剂组件的子元素?

How to access Reagent Component's children elements correctly?

我是 clojure/Clojurescript 初学者。这是关于我的第一个 Luminus 网络应用程序与 Reagent。 我设法通过迭代填充了 8 个上传按钮,并最终使用 reagent/render-component 函数。

我在循环中有以下打嗝结构,所有循环项目都是 return 作为反应组件。

(let [state_ (reagent/atom (into [] (take 8 (repeat "img/image.png"))))
      state' @state_
      ad-box
      [:div {:class "col-md-3 ui segment "}
       [:img {:class "ui small image"
              :src (nth state' idn)}]
       [:div {:class "ui icon buttons"}
        [:button {:class "ui green button img-btn s-btn"}
         [:i {:class "fa fa-picture-o"}]]
        [:input {:class "inputfile"
                 :type "file"
                 :id (str "ad-pic-" idn)
                 :name (str "ad-pic-file-" idn)
                 :on-change (fn [e]
                              (this-as this
                                (let [el this
                                      name (.-name el)
                                      file (aget (.-files el) 0)
                                      form-data (doto
                                                    (js/FormData.)
                                                    (.append name file))]
                                  (POST "/upload-pics"
                                        {:headers {"x-csrf-token"
                                                   (.-value (.getElementById js/document "token"))}
                                         :body form-data
                                         :response-format :json
                                         :keywords? true
                                         :handler handle-response-ok
                                         :error-handler handle-response-error})
                                  (set-upload-indicator))))}]
        [:button {:class "ui disabled button img-btn r-btn" }
         [:i {:class "fa fa-times"}]]]]]
  ad-box)

创建作为 type="file" 行为的组件上传按钮后。但问题是我无法通过 ajax 请求将上传的文件参数发送到后端。

抱歉这个问题太长了。如果您能调查一下,我将不胜感激。谢谢

使用:

(-> e .-target .-files (aget 0))

而不是:

(aget (.-files el) 0)