Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pug `#{}` fails to load variable inside `onclick`

So I am using a javascript object to render a list of items. My object looks like this:

{
            text: 'One',
            url: 'index.pug'
        },
        {
            text: 'Two',
            url: 'Two.pug'
        },
        {
            text: 'Three',
            url: 'Three.pug'
        }
}

The interesting part is when pug renders them. I am rendering them using something like this:

div
    ul.horizontalScroll
        each item in params.apps
            li
                a(onclick="loadXMLDoc(#{item.url})") #{item.text}

What I cannot figure out is why item.text renders correctly, but on click the link doesn't ping the function. In chrome inspector, I saw this:<a onclick="loadXMLDoc(#)">One </a>. Why is the argument not coming through as index.pug like it should??

like image 316
Ethan Avatar asked Jul 01 '16 15:07

Ethan


People also ask

Is a pug a good pet to have?

Pugs are known for making wonderful pets for all kinds of people and home environments. They are friendly dogs that get along well with everyone, including strangers, so don't count on a pug to be a good guard dog. They are mischievous dogs that are highly adaptable and loving.

Do pugs suffer their whole lives?

The research also showed pugs have a reduced risk of some conditions, including heart murmur, aggression and wounds. But researchers suggest their findings indicate many pugs may suffer from seriously compromised health and welfare.

Why pugs should not be bred?

The pug was selectively bred to feature an extremely flat face, which contributes to breathing difficulties and eye injuries. Disorders like hip dysplasia, commonly seen in large purebreds, such as German Shepherds have emerged due to the breeder's desire for a sloping back.

Why are pugs so good?

Pugs are ideal for families with children, as they are generally patient with children and love to play games. The shape of their mouth prevents them from biting efficiently, and this makes them reasonably harmless. Pugs are among the most gentle and passive of all breeds.


1 Answers

Try concatenating the variable within the attribute:

a(onclick="loadXMLDoc('" + item.url + "')") #{item.text}
like image 110
Seth Avatar answered Sep 25 '22 02:09

Seth