- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从我的 Reagent 应用程序执行 Ajax GET,以从数据库加载一些内容。
我不完全确定获取此类 ajax 调用结果到我的页面的最佳方法是什么,考虑到如果我将其放入原子中,那么当取消引用原子时,Reagent 会自动重新渲染组件,这意味着我得到了无限的 ajax 调用序列。
对于一些代码,
(def matches (atom nil))
(defn render-matches [ms]
(reset! matches (into [:ul] (map (fn [m] ^{:key m}[:li m])
(walk/keywordize-keys (t/read (t/reader :json) ms)))))
这个函数基本上创建了一个[:ul [:li "Stuff here"] [:li "And here"]]
我希望将其显示在我的页面上,该页面现在具有以下代码。
(defn standings-page []
(GET "/list-matches"
{:handler render-matches})
@matches)
最佳答案
我认为最好只将数据保存在原子中,并生成 HTML 作为组件逻辑的一部分。
此外,最好在渲染阶段之外触发 AJAX 调用,例如,在组件安装之前,或者作为事件的结果(例如单击按钮)。
像这样:
(def matches (atom nil))
(defn component []
(let [get-stuff (fn [] (GET "/..." :handler (fn [response]
(reset! matches (:body response))))]
(get-stuff) <-- called before component mount
(fn []
[:ul
(for [m match]
^{:key ...}
[:li ...])])))
这在 this post 中称为 form-2 .
关于使用试剂进行 Ajax GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30060533/
我正在尝试将初始焦点设置在输入元素上 (defn initial-focus-wrapper [element] (with-meta element {:component-did-mo
我有一个 html Canvas ,想在上面显示 Quil 草图。大多数 Quil 示例使用 defsketch 在静态 html 页面上定义的 Canvas 上进行绘制。我想在这个试剂组件中的 Ca
我有一个 html Canvas ,想在上面显示 Quil 草图。大多数 Quil 示例使用 defsketch 在静态 html 页面上定义的 Canvas 上进行绘制。我想在这个试剂组件中的 Ca
我正在尝试通过一个简单的绘图程序来掌握 clojurescript 中的试剂。 我正在寻找一个示例,说明如何使用 Reagi 以有原则的“FRP”风格访问鼠标位置。 . 在各种试剂示例中,我可以看到如
所以签名为component-will-receive-props就是这样: https://github.com/reagent-project/reagent/blob/master/src/re
我从 here 复制了一个两年前的要点.它现在与 Figwheel 一起工作,并使用更新版本的 Reagent/React。 我正在寻找一种通用方法来隔离出现在 Javascript 控制台中的此警告
如何将不同的 React 版本与 Reagent、Om、Rum、Quiescent 或 Brutha 一起使用? 最佳答案 self 回答,因为这个问题经常被问到: 首先,您必须告诉 Leininge
我是一名优秀的程序员,十分优秀!