我试图在我的网页中嵌入一个 CodeMirror 来编辑几个代码片段,一次一个。
为此,我:
node-defs-atom
拥有一个包含代码片段图的Reagent atom 。- 有另一个原子
node-history-atom
,其中包含正在查看的片段的键 - 将 CodeMirror 的值设置为键处的代码映射的值。
这是不起作用的:
(defn editor [node-defs-atom node-history-atom]
(reagent/create-class
{:reagent-render (fn [] (do [:textarea
{ :value (@node-defs-atom (last @node-history-atom))
:auto-complete "off"}]))
:component-did-mount (editor-did-mount node-defs-atom node-history-atom)
}))
(defn editor-did-mount [node-defs-atom node-history-atom]
(fn [this]
(let [codemirror (.fromTextArea js/CodeMirror
(reagent/dom-node this)
#js {:mode "clojure"
:lineNumbers true})]
...... )))
更改node-history-atom
withreset!
对 CodeMirror 中的文本没有任何作用。我真的不确定出了什么问题。
如果有人能告诉我应该在哪里引用,(@node-defs-atom (last @node-history-atom))
我将不胜感激。
提前致谢!