【问题标题】:Syntax for giving a button a particular width赋予按钮特定宽度的语法
【发布时间】:2015-12-23 16:26:17
【问题描述】:

如何将按钮设置为特定宽度?这是我迄今为止尝试过的事情之一:

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

设置按钮的标题效果很好,可能与这个问题无关。我把它留在里面是因为这是一个典型的事情,而且属性的位置可能很重要。

leinproject.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"] 

【问题讨论】:

    标签: clojurescript om figwheel


    【解决方案1】:

    我认为问题是由于#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

    【讨论】:

      【解决方案2】:

      我得到了它的工作:

      (defui HelloWorld
        Object
        (render [this]
           (dom/button (clj->js {:style {:width 300}}) (get (om/props this) :title))))
      

      注意clj->js的使用。

      【讨论】:

        猜你喜欢
        • 2012-03-22
        • 2011-07-09
        • 1970-01-01
        • 1970-01-01
        • 2014-05-08
        • 2019-03-12
        • 2012-06-18
        • 1970-01-01
        • 2012-08-03
        相关资源
        最近更新 更多