0

ホームページにテキストボックスを作成したいので、次のように書きました。

(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]]ただし、コードから削除すると、Web ページが通常どおり読み込まれるという問題が発生します。このコード行では何も起こりません。

私は自分の間違いを理解できず、助けていただければ幸いです。

(PSが役立つ場合は、luminusフレームワークを使用しています)

4

1 に答える 1

1

投稿したコードを見ると、フィールドの値が key の下に格納される場所を含むfields必要があるようです。コードは多かれ少なかれ次のようになります。atommapid

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

これがお役に立てば幸いです。

于 2016-11-03T18:05:14.513 に答える