Clojurescript - 文本框中的占位符

时间:2016-11-02 15:10:34

标签: clojure clojurescript luminus

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

(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]],网页会正常加载。用这行代码没有任何反应。

我无法弄清楚我的错误,任何帮助都会受到赞赏。

(P.S我正在使用一个发光框架,如果有任何帮助的话)

1 个答案:

答案 0 :(得分:1)

查看您发布的代码,看起来fields应该是包含atom的{​​{1}},其中字段的值将存储在密钥map下。代码应该或多或少看起来像这样:

id

我希望这证明是有帮助的。