【问题标题】:Clojurescript - Placeholder in text boxClojurescript - 文本框中的占位符
【发布时间】:2016-12-16 14:47:28
【问题描述】:

我想在我的主页上创建一个文本框,所以我写了以下内容:

(defn home-page []   
    [:div.container    
        [:h1 "Enter Code:"]    
        [c/text-input "id" :id "enter code" fields]])

c/text-input 包含在我需要的另一个命名空间 (common.cljs) 中。

common.cljs 命名空间中的代码如下:

(defn input [type id placeholder fields]
  [:input.form-control.input-lg
   {:type        type
    :placeholder placeholder
    :value       (id @fields)
    :on-change   #(swap! fields assoc id (-> % .-target .-value))}])

(defn form-input [type label id placeholder fields optional?]
  [:div.form-group
   [:label label]
   (if optional?
     [input type id placeholder fields]
     [:div.input-group
      [input type id placeholder fields]
      [:span.input-group-addon
       "✱"]])])

(defn text-input [label id placeholder fields & [optional?]]
  (form-input :text label id placeholder fields optional?))

但是,如果我从代码中删除[c/text-input "id" :id "enter code" fields]],网页会正常加载,就会出现我的问题。有了这行代码,什么都没有发生。

我无法弄清楚我的错误,我们将不胜感激。

(如果有帮助,我正在使用 luminus 框架)

【问题讨论】:

  • 您能在浏览器控制台窗口中看到任何错误消息吗?
  • 我收到一条错误消息,指出字段是未使用的参数,但我不知道该放什么

标签: clojure clojurescript luminus


【解决方案1】:

查看您发布的代码,看起来fields 应该是包含mapatom,其中字段的值将存储在键id 下。代码应该或多或少像这样:

(defn home-page []
  (let fields (atom {})
    [:div.container
      [:h1 "Enter Code:"]
      [c/text-input "id" :id "enter code" fields]]))

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2020-05-27
    • 2015-12-15
    • 2011-07-29
    • 2023-04-08
    • 2015-12-15
    • 2021-12-21
    • 2014-02-14
    • 2013-06-07
    • 2017-11-29
    相关资源
    最近更新 更多