Jade, how to escape hash character?

为君一笑 提交于 2020-01-06 15:51:06

问题


I have the following line in my Jade template:

img(src='#{similarArtist.image[0].#text}')

Do not ask me why Last.fm guys decided it was a good idea to use a name starting with hash in JSON document, but this is what I am dealing with.

It seems the 2nd hash sign trips up Jade. Maybe it expects two braces afterwards? I have tried prepending it with a backslash character (traditionally an escape operator) but that did not help.

So what can I do in this case? I really need to access that #text property.


回答1:


The # is not allowed in dot notation but you can use array notation for that. You can simply do:

img(src='#{similarArtist.image[0]['#text']}')



回答2:


Not very beautiful solution but it works:

!= '<img src=' + similarArtist.image[0]['#text'] + '>'


来源:https://stackoverflow.com/questions/20486190/jade-how-to-escape-hash-character

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