meteor-jade icon indicating copy to clipboard operation
meteor-jade copied to clipboard

Accessing Array Content

Open igregson opened this issue 10 years ago • 3 comments

This works:

 {{emails.[0].address}}

This doesn't:

#{emails.[0].address}

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

igregson avatar Nov 14 '14 16:11 igregson

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.

mquandalle avatar Nov 21 '14 14:11 mquandalle

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

lagden avatar Dec 04 '14 03:12 lagden

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.

sylido avatar Apr 07 '15 00:04 sylido