3

我有一个照片链接列表,想用 clojure 和 noir 生成 img 标签。

在这里我得到链接:

(def photos
(->> (get-in result ["photoset" "photo"]) (map #(str "http://farm"(get % "farm")
".staticflickr.com/"(get % "server")"/"(get % "id")"_"(get % "secret")"_b.jpg"))))

结果:

(http://farm9.staticflickr.com/8087/8455893107_1a3236df06_b.jpg http://farm9.staticflickr.com/8235/8469482476_4c1bf59214_b.jpg)

然后我尝试从该列表中生成 img 标签:

(defpage "/" []
 (mylayout/layout
 (doseq [e photos] (prn e))
 ))

  (调用(defpartial layout [& content] ...)

我正在尝试为基于黑色的站点中的每个链接获取以下输出:

[:img {:src "url"}]

我正在尝试这个但没有成功:

(doseq [e photos] ([:img {:src e}]))

如何将链接传递给布局以生成 img 标签?

谢谢!

4

1 回答 1

4

Either of these should work:

(map #(vector :img {:src %}) photos)

(for [url photos]
  [:img {:src url}])

Edit: As Chuck mentioned, doseq is for side-effects. You are wanting to "collect" the results and send them to the template. To do this you need to use list comprehension like for or just map over your collection.

I hate to rain on your parade but just so you know, noir has been deprecated

于 2013-02-13T20:44:38.567 回答