2016-11-02 53 views
0

我要创建我的主页文本框,所以我写了下面的:Clojurescript - 占位符文本框中

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

在C /文本输入包含在另一个命名空间(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]]加载网页时为正常。这行代码没有任何反应。

我无法弄清楚我的错误和任何帮助,将不胜感激。

(PS我使用的是Luminus公司的框架,如果这是任何帮助)

+0

您是否可以在浏览器控制台窗口中看到任何错误消息? – kp2222

+0

我收到一个错误,表示字段是一个未使用的参数,但我不知道该放在什么位置 – rbb

回答

1

看着你发布的代码,它看起来像fields应该包含map其中字段的值将被存储在​​根据关键id。代码应该看起来或多或少像这样:

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

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