我有一个字符串列表,我想用Handlebars.js显示
到目前为止,这似乎是不可能的,尽管这应该是这种情况似乎很荒谬.
产品对象的示例是:
"product": { "name": "top TP-209-NAV","category": "Top","brand": "Living Dolls","description": "Fabric : Navy-white stretch cotton Long sleeves top (can be worn as dress)","price": "23.0","tags": [ "Slips on"," stretch cotton"," long sleeves" ],"image1": { "src": "http://www.livingdolls-closet.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/T/P/TP-209-NAV-1-living-dolls-top_1.jpg","ratio": 1.5 } },
当我做这样的事情时,我可以看到适当数量的逗号,表明列表正在迭代,但是我无法弄清楚如何显示实际的标签项.
{{#product.tags}}<a href="">{{val}}</a>,{{/product.tags}}
解决方法
我只需要使用每个助手..
{{#each product.tags}}<a href="">{{this}}</a>,{{/each}}