Unable to display two components in OM

折月煮酒 提交于 2019-12-07 09:34:19

问题


I am attempting to learn Om, and have come across something I don't understand. I would expect this code

(defn search-page-view [app owner]
(reify
    om/IRender
    (render [_]
      (dom/div #js {:id "search-block"}
                  "Test")
      (dom/div #js {:id "results-block"}
               "Test2"))))
(om/root
 search-page-view app-state
  {:target (. js/document (getElementById "app"))})

to result in this html:

<div id="app>
  <div id="search-block">
    Test
  </div>
  <div id="results-block">
    Test2
  </div>
</div>

However, it does not! The first div containing Test does not display. What am I misunderstanding?

Edit with the solution (pointed out by FakeRainBrigand):

Changing the code to

(defn search-page-view [app owner]
  (reify
    om/IRender
    (render [_]
      (dom/div nil
               (dom/div #js {:id "search-block"}
                    "Test")
               (dom/div #js {:id "results-block"}
                    "Test2")))))

results in the expected html.


回答1:


As explained here and by FakeRainBrigand explained, your render function must return a single renderable.



来源:https://stackoverflow.com/questions/24448551/unable-to-display-two-components-in-om

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!