使用单词和索引作为密钥,在Clojure和打ic中添加独特的键

发布于 2025-02-02 04:46:02 字数 291 浏览 3 评论 0原文

我有一个快速的问题。我正在从事一个Clojure项目。我想在每个LI标签中添加唯一的密钥,例如:

(defn test [text]
    [:li {:key :index} text])

如何设置诸如“ hi+index ”之类的键?

我试过

{:key(str“ hi”索引)}

但它不起作用。我是Clojure和Hiccup的新手。

非常感谢。

I have a quick question. I'm working on a Clojure project. I want to add unique key to each li tag, like this:

(defn test [text]
    [:li {:key :index} text])

How I can set keys like "hi+index"?

I tried

{:key (str "hi" index)}

but it does not working. I'm new to Clojure and hiccup.

Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬色的秋千 2025-02-09 04:46:02

您在某个地方犯了一个错误。如有疑问,请使用一些测试代码询问计算机:

  (doseq [idx (range 5)]
    (prn (str "hi-" idx)))

结果,

"hi-0"
"hi-1"
"hi-2"
"hi-3"
"hi-4"

我喜欢使用此模板项目< /a>用于如上所述的快速测试。只需克隆它,然后将一些示例代码扔进test/clj/tst/demo/core.clj
档案,走开了!

You are making a mistake somewhere. When in doubt, ask the computer with some test code:

  (doseq [idx (range 5)]
    (prn (str "hi-" idx)))

with result

"hi-0"
"hi-1"
"hi-2"
"hi-3"
"hi-4"

I like to use this template project for quick tests like the above. Just clone it and throw some sample code into the test/clj/tst/demo/core.clj
file, and away you go!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文