You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Reagent组件传递数据时所有modal绑定id重复问题排查

问题原因
  • 核心问题是所有modal-button组件的第一个入参(modal唯一标识)都硬编码为固定值:argument,导致页面中所有argument对应的modal共享同一个ID
  • re-frame的modal显隐状态是通过ID来匹配的,相同ID的modal的显隐状态完全同步,同时多个相同ID的modal渲染时,你看到的内容永远是最后一个循环渲染生成的modal的内容,所以所有弹窗都会显示同一个ID
解决方案

修改arguments-component中调用modal-button的代码,将固定的modal ID替换为和当前argument ID绑定的唯一值即可:

(defn arguments-component [list-of-args]
  [:ul.arguments
   (for [{:keys [comment upvotes id]} @list-of-args]
     ^{:key id}
     [:li
      [:p comment]
      [:p upvotes]
      [:p id
       ;; 把固定的:argument替换为和当前id绑定的唯一值
       [modal-button (keyword (str "argument-" id))
       ;title
        "Comments"
       ;body
        [:div
         [:p "Comments"]
         [comments-component id]]
        ;footer
       [:p "OpinionNeeded"] ]]])])

修改后每个argument对应的modal都有唯一ID,点击不同按钮会激活对应ID的modal,就能正确显示对应argument的ID和关联评论。

内容的提问来源于stack exchange,提问作者gash_

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 14:54:03