【问题标题】:How to access Reagent Component's children elements correctly?如何正确访问试剂组件的子元素?
【发布时间】:2016-10-28 11:43:06
【问题描述】:

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

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

(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请求将上传的文件参数发送到后端。

很抱歉这个问题太长了。如果你能调查一下,我非常感激。谢谢。

【问题讨论】:

    标签: jquery reactjs clojure clojurescript reagent


    【解决方案1】:

    用途:

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

    代替:

    (aget (.-files el) 0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 2019-07-07
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      • 1970-01-01
      • 2020-09-25
      相关资源
      最近更新 更多