mquandalle / meteor-jade

The Jade template engine for Meteor/Blaze
http://atmospherejs.com/mquandalle/jade
MIT License
307 stars 39 forks source link

Accessing Array Content #88

Open igregson opened 9 years ago

igregson commented 9 years ago

This works:

 {{emails.[0].address}}

This doesn't:

#{emails.[0].address}

Is this a bug with meteor-jade or is my syntax wrong?

mquandalle commented 9 years ago

Is that something we want? It's not a valid JavaScript syntax, the normal syntax should be #{emails[0].address}. I'm not sure if it already works today, but if it doesn't you can still use the spacebars alternative. I don't think I want to support the #{emails.[0].address} syntax in jade.

lagden commented 9 years ago

I know that meteor-jade behavior is little different of pure jade, but I think you wrote wrong!!

- var emails = [{"name": "a", "address": "a@a"}, {"name": "b", "address": "b@b"}]

p #{emails[0].name} - #{emails[0].address}
p #{emails[1].name} - #{emails[1].address}

hr

ul
  each email in emails
    li #{email.name} - #{email.address}

http://codepen.io/lagden/pen/QwjojM?editors=100

sylido commented 9 years ago

I think Meteor used to allow emails.0.address at around 0.7, but switched to emails.[0].address with Blaze at 0.8+, probably some weirdness when parsing through complex objects/arrays ?

Either way for consistency sake why not do #{emails.0.address} at least ? Also the valid javascript syntax would be emails[0].address if we want to equate it to that one.

At least a note about array/object access would be really nice - I had to google foo this hard for 15+ minutes.