Jamie Bradley
Jamie Bradley

Reputation: 669

How Do I Access an Object Property By Index Using Spacebars in Meteor?

Anyone know how to access a numeric property with Meteor spacebars?

Upvotes: 2

Views: 175

Answers (2)

Keith Dawson
Keith Dawson

Reputation: 1495

Glad to hear that you figured it out on your own. Not sure if you happened to see it, but the documentation for Spacebars can be found here. The section that covers the issue you have identified in your original question is called Identifiers and Paths near the top of the page.

Per the documentation, in order to access a specific index in a data context object, the numeric index must be enclosed in brackets like so:

foo.[0]

Upvotes: 2

Jamie Bradley
Jamie Bradley

Reputation: 669

After some guess work I sussed it out as I was writing the question! Let's say you have a 'size' object like so, and you want to access 70.

size: {
 70: 10,
 10: 80,
 20: 10
}

Use the following in your template file:

{{size.[70]}} // Will return 10

Upvotes: 3

Related Questions