gpt4 book ai didi

clojurescript - 如何创建 appendChild 试剂元素?

转载 作者:行者123 更新时间:2023-12-04 03:39:09 24 4
gpt4 key购买 nike

例如:

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

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

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

最佳答案

(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")))

关于clojurescript - 如何创建 appendChild 试剂元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42142239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com