所以我開始學習clojurescript,我正在檢查它的不同教程。我無法發現的一件事是在某個html文件上定位一個元素id來放置我的標記。Clojurescript OM定位元素在不同的html上
比方說,我有兩個html文件,index.html和about.html。我想針對下面的元素ID「應用程序」我的代碼上about.html當URL指向http://localhost:3449/about
代碼:
(om/root
(fn [data owner]
(reify
om/IRender
(render [_]
(dom/p nil (:text data)))))
app-state
{:target (. js/document (getElementById "app"))})
什麼是做到這一點的最好辦法?或者可能是一個參考,所以我可以看看它。或者也許我在這裏錯過了一些觀點,也許有人可以啓發我。
此外,我已經嘗試使用此https://github.com/gf3/secretary,但我不確定是否更好的方法,因爲網址必須有一個hashkey(http://localhost:3449/#/about)才能觸發。
更新:
所以我用下面的答案和它的工作,但是我做它的工作之前,面臨着一些問題。在任何情況下,有人遇到這個帖子,並已使用下面的答案,但得到一個未定義的問題檢查我的最終代碼。您project.clj
:cljsbuild {:builds [{ :id "dev" :source-paths ["src/clj" "src/cljs"] :compiler {:output-to "resources/public/js/main.js" :output-dir "resources/public/js/out/" :optimizations :none :pretty-print true}}]}
:cljsbuild
部分列入about.html
<script src="js/out/goog/base.js" type="text/javascript"></script> <script src="js/main.js" type="text/javascript"></script> <script type="text/javascript">goog.require("om_async.about");</script> <script type="text/javascript">om_async.about.init();</script>