0

到目前为止,我已经设法弄清楚如何使用 clone-for 复制一个 div,但是我还没有找到一个在 deftemplate 宏内部有条件地应用转换的函数。

(deftemplate threads "thread.html" [xs]
  [:div.entry] ;hook to a div
  (clone-for [x xs] ;for each in the array passed in
      (if (contains? x :picture) ;if picture in object
        ([:div.entry :> :img] (set-attr :src (:picture x))) ;show picture
        ([:div.entry] (set-attr :style "display:none;"))) ;else hide element
      ;do more things here
      ))

(threads [{:picture 'link goes here'},{},...])

返回

java.lang.IllegalArgumentException: Key must be integer

我想知道是否有更有经验的人可以提供帮助?我不确定以下应该写成什么。

  (if (contains? x :picture) ;if picture in object
        ([:div.entry :> :img] (set-attr :src (:picture x))) ;show picture
        ([:div.entry] (set-attr :style "display:none;"))) ;else hide element

编辑:在艾伦的建议下,我在下面评论并删除了与我的问题无关的代码。

4

0 回答 0