无法在渲染阶段之外操纵光标

Far*_*ion 5 clojurescript om

尝试第一次做出反应,我想做一个简单的待办事项列表应用程序.但每次按下Enter键都会触发onSubmitUncaught Error: Cannot manipulate cursor outside of render phase, only om.core/transact!, om.core/update!, and cljs.core/deref operations allowed.虽然我认为这是一个非常好的错误信息,但我不知道该怎么做.

(ns app.core
  (:require [om.core :as om :include-macros true]
            [sablono.core :as html :refer-macros [html]]))

(def app-state (atom
                {:todos [{:todo "first"}
                         {:todo "second"}]
                 :current ""}))

(defn to-do
  [data]
  (om/component
   (html [:li (:todo data)])))

(defn to-dos
  [data]
  (om/component
   (html [:div
          [:form {:on-submit (fn [e]
                               (.preventDefault e)
                               (om/transact! data :todos (fn [v]
                                                           (js/console.log (:current data))
                                                           (conj v (:current data)))))}
           [:input {:type "text" 
                    :placeholder "Enter some text."
                    :on-change (fn [e] (om/update! data :current (.. e -target -value)))}]]
          [:ul 
          (om/build-all to-do (:todos data))]])))

(om/root to-dos app-state {:target js/document.body})
Run Code Online (Sandbox Code Playgroud)

edb*_*ond 4

我认为问题是你data在om/transact内访问的地方!你应该在哪里操作v:

(:current v) 代替 (:current data)

或者你可以尝试(:current @data)最新的数据价值