gpt4 book ai didi

recursion - 递归组件在 Om 中工作时遇到问题?

转载 作者:行者123 更新时间:2023-12-02 22:58:41 25 4
gpt4 key购买 nike

我有以下内容:

(ns commentz.client
(:require
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[clojure.browser.repl]))

(def app-state
(atom
{:id "a"
:value "I am the greatest of comments!"
:user "1"
:anonymous false
:score 10
:children
[{:value "I am ok too."
:user "1"
:anonymous false
:score 4
:children
[{:value "I am the second greatest comment"
:user "2"
:anonymous false
:score 7
:children {}}]}
{:value "I like turtles"
:user "3"
:anonymous true
:score -3
:children {}}]}))

(defn header [app owner]
(dom/div #js {:className "header"}
(dom/div #js {:className "vote"}
(dom/div #js {:className "up"})
(dom/div #js {:className "down"}))
(dom/a #js {:className "username" :href (:user app)} (:user-name app))
(dom/div #js {:className "score"} (:score app))))

(defn footer [app owner]
(dom/div #js {:className "footer"}
(dom/a #js {:className "permalink" :href (str "#" (:id app))} "permalink")
(dom/a #js {:className "reply"} "reply")))

(defn comment [app owner]
(reify
om/IRender
(render [this]
(dom/div {:id (:id app) :className "comment"}
(header app owner)
(dom/div #js {:className "value"} (:value app))
(footer app owner)
(om/build-all comment (:children app))))))

(om/root comment app-state {:target (. js/document (getElementById "app"))})

上面的代码确实成功编译,但我没有看到任何递归。相反,当我使用浏览器检查时,我看到以下内容。

10 
I am the greatest of comments!
permalink reply
0 32374988

我认为 32374988 可能是一个对象哈希,不确定 0 是什么意思。不管怎样,我的目的是看到所有 4 条评论都显示出来,其中一些评论嵌套在其他评论中。目前我只得到根注释,加上一些奇怪的 0 32374988 ,其中递归构建的注释应该在。任何帮助表示赞赏。谢谢。

最佳答案

(om/build-all) 返回一个 seq。尝试(应用 dom/div nil ...)

(apply dom/div {:id (:id app) :className "comment"}
(header app owner)
(dom/div #js {:className "value"} (:value app))
(footer app owner)
(om/build-all comment (:children app))))))

关于recursion - 递归组件在 Om 中工作时遇到问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22724725/

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