问题
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