代码之家  ›  专栏  ›  技术社区  ›  phlie

如何在Hoplon中切换标签

  •  0
  • phlie  · 技术社区  · 7 年前

    如果我有以下代码和一个从“p”标记切换到“h1”标记的函数:

     (def switch-tag (cell p))
    

     ((cell= switch-tag) "Text goes here")
    

    1 回复  |  直到 7 年前
        1
  •  1
  •   akond    7 年前

    我一直无法用你的方式解决这个问题。这里有一个解决方法:

    (page "index.html")
    
    (def key! (cell true))
    
    (defelem my-elem [_ [child]]
             (cell= (if key! (h1 child) (p child))))
    
    (html
        (body
            (button :click #(swap! key! not) "test")
            (my-elem "this is a test")))
    
    推荐文章