赋予按钮特定宽度的语法
问题描述:
如何将按钮设置为特定宽度?这是到目前为止,我已经尝试的事情之一:赋予按钮特定宽度的语法
(:require [om.next :as om :refer-macros [defui]]
[om.dom :as dom])
(defui HelloWorld
Object
(render [this]
(dom/button #js {:style {:width 300}} (get (om/props this) :title))))
设置按钮的标题工作正常,可能是不相关的这个问题。我已经把它留下了,因为这是一个典型的做法,并且放置属性可能很重要。
雷音project.clj
文件具有这些依赖关系:
[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.170"]
[org.omcljs/om "1.0.0-alpha24"]
[figwheel-sidecar "0.5.0-SNAPSHOT" :scope "test"]
答
我认为这个问题是由于#js只能在顶层工作。 #JS将在顶层地图或矢量[]上工作,但是如果您将数据嵌套为值,则需要为每个嵌入对象包含额外的#js调用。
你真正需要的是
(:require [om.next :as om :refer-macros [defui]]
[om.dom :as dom])
(defui HelloWorld
Object
(render [this]
(dom/button #js {:style #js {:width 300}} (get (om/props this) :title))))
看一看this后使用#js。为了便于阅读,而不是嵌套的#js调用,您通常更适合使用clj-> js
答
我得到了它的这项工作:
(defui HelloWorld
Object
(render [this]
(dom/button (clj->js {:style {:width 300}}) (get (om/props this) :title))))
注意使用clj->js
。