Reputation: 310
I am trying to display content of two sequences on web page. First one of them contains name of the picture, and the second one contains URL to the image. The problem's start when I try to iterate through these two lists (using foreach-like for loop) - this result in either multiple picture names, or multiple pictures (in short, a total mess). Here is example of my page rendering code (sequences are converted to vector using (vec(flatten (sequence)))
):
(defn view-output []
(view-layout
[:h2 "default images"]
[:form {:method "post" :action "/"}
( for [manganame ["image1" "image2"]]
[:input {:type "text" :value manganame}])
(for [manga-image["image1URL" "image2URL"]]
[:img {:src manga-image}[:br] [:br][:br]]) ] ))
This code will first display names, then pictures. Can anyone suggest a way for inserting these values next to each other, ot on top of each other (perhaps table like implementation)
Image_name1
Picture1
Image_name2
Picture2
or
Image_name1 Image_name2
Picture1 Picture2
Thanks
Upvotes: 0
Views: 108
Reputation: 17299
(mapcat (fn [manganame mangaimage]
[[:input {:type "text" :value manganame}]
[:img {:src mangaimage}]
[:br] [:br] [:br]])
["image1" "image2"]
["image1URL" "image2URL"])
gives
([:input {:type "text", :value "image1"}]
[:img {:src "image1URL"}]
[:br] [:br] [:br]
[:input {:type "text", :value "image2"}]
[:img {:src "image2URL"}]
[:br] [:br] [:br])
Upvotes: 1
Reputation: 8591
I just realized that the correct code is:
(defn view-output []
(view-layout
[:h2 "default images"]
[:form {:method "post" :action "/"}
(interleave
(for [manga-name ["image1" "image2"]]
[:input {:type "text" :value manga-name}])
(for [manga-image["image1URL" "image2URL"]]
[:img {:src manga-image}[:br] [:br][:br]]))]))
As you want a list of [:input][:img][:input][:img].
My previous answer was returning [:input :img][:input :img]:
(defn view-output []
(view-layout
[:h2 "default images"]
[:form {:method "post" :action "/"}
(for [[manganame manga-img] (map vector ["image1" "image2"] ["image1URL" "image2URL"]))]
(concat
[:input {:type "text" :value manganame}]
[:img {:src manga-image} [:br ] [:br ] [:br ]]))]))
Upvotes: 2