如何创建appendChild试剂元素?

时间:2017-02-09 16:43:30

标签: clojurescript reagent

例如:

    (defn place-background []
      [:div {:class "pbackground" 
             :style {:height (:fullheight @app-state)}}])

    (reagent/render-appendChild [place-background]
                          (. js/document (getElementById "container")))

因为如果我使用render-component,它将替换内容

1 个答案:

答案 0 :(得分:3)

(ns reagenttest.core
    (:require [reagent.core :as r]))


(defn sample-comp []
    [:div "hello there!"])

(defn appended-container [target]
    (let [id "some-unique-id"
          container (.getElementById js/document id)]

        (if container
            container
            (.appendChild target (doto (.createElement js/document "div")
                                     (-> (.setAttribute "id" id))))
            )))

(r/render [sample-comp] (appended-container (.getElementById js/document "app")))