iterate over an array of objects in jade/pugjs

…衆ロ難τιáo~ 提交于 2019-12-18 14:52:15

问题


I have the following json object:

 var partners =[{ "name":"partnerx", "image": "imagex" }, { "name": "partnery", "image": "imagey" }]

I want to put into a ul object using jade and I tried:

ul#slides.swiper-wrapper
   mixin partners(name, image)
    li.swiper-slide
       img(src=#{image} , alt=#{name})

This is not working.


回答1:


Try this:

ul#slides.swiper-wrapper
   each partner in partners
     li.swiper-slide
       img(src=partner.image, alt=partner.name)

https://pugjs.org/language/iteration.html



来源:https://stackoverflow.com/questions/24316772/iterate-over-an-array-of-objects-in-jade-pugjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!