第一次尝试使用react,我想制作一个简单的待办事项 list 应用程序。但是每次我按Enter触发onSubmit
时都会说Uncaught 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})
最佳答案
我认为问题是您在om/transact中访问data
的地方!您应该在v
上进行操作的地方:(:current v)
代替(:current data)
或者您可以尝试(:current @data)
获取最新数据值
关于clojurescript - 无法在渲染阶段之外操作光标,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24548626/